【问题标题】:How do I handle results of Shodan search with python如何使用 python 处理 Shodan 搜索的结果
【发布时间】:2023-02-11 20:20:31
【问题描述】:

我想在另一个命令中使用这个 Shodan 搜索的结果。

它确实返回我想要的信息,因为它是当前的。

我试过分配给一个变量但无法让它工作。

import shodan

SHODAN_API_KEY = "$apikey"

api = shodan.Shodan(SHODAN_API_KEY)

try:

    results = api.search('$ipaddress')

    print('Results found: %s' % results['total'])
    for result in results['matches']:
            print('%s' % result['ip_str'])
            print('%s' % result['port'])
            print('%s' % result['hostnames'])
except shodan.APIError as e:
        print ('Error: %s' % e)

【问题讨论】:

  • 你的意思是results = api.search('$ipadress')没有把搜索结果赋值给一个变量?
  • 不,我尝试将整个命令分配给一个变量但无法让它工作(不确定你是否可以在 python 中这样做,srry 有点菜鸟)。该命令按原样工作以返回通过 Shodan 可用的外部 IP 地址的开放端口和主机名。
  • 是的,因为您只打印结果。因此,在另一个命令中,您可以再次执行此 for 循环以准确检索您想要的内容。 for result in result['matches']: if result[index] == something: do something 或类似的东西。请记住,这只是一个例子。如果您可以提供有关预期输出等的更多信息,则可以提供更多帮助。编辑:刚刚检查的匹配项是一个字典,所以需要做 for key, value in result: if key == something: do something 类似的事情。取决于您想做什么以及要使用输出的哪一部分。
  • 如果你想获取有关 IP 的信息,只需执行以下操作:``` api = shodan.Shodan(API_KEY) info = api.host('1.1.1.1') print(info) ``` 这是有关如何操作的官方文章它:help.shodan.io/developer-fundamentals/looking-up-ip-info

标签: python shodan


【解决方案1】:

只需将括号人添加到打印命令

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多