Shodan Python语法使用“Info”标记

2024-05-20 14:16:32 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我目前正在使用import shodan在Python中使用Shodan编写一个脚本。 周围的文档不是最好的,所以我想我应该把我的问题带到这里

使用Shodan CLI有一个名为Shodan Info的命令,该命令显示您的帐户剩余的搜索积分数

当查看Shodan Documentation时,我可以看到有一个info()标记,但是每当我使用它时,就会出现一个错误

是否有人知道在python脚本中使用info来显示帐户信用数的正确语法?

我收到的错误:

ipinfo = shodan.info()
print (ipinfo)

错误

Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XX Documents/XXXX/Working 
                                             Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.info()
AttributeError: module 'shodan' has no attribute 'info'

ipinfo = shodan.Shodan(info())
print (ipinfo)

错误

Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XXXXDocuments/XXXXXX/Working 
                                             Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.Shodan(info())
NameError: name 'info' is not defined

Tags: 命令info脚本most错误帐户documentsipinfo
2条回答

您需要实例化Shodan类,然后才能使用它的Shodan.info()方法。下面是它在官方命令行界面中的外观:

https://github.com/achillean/shodan-python/blob/master/shodan/__main__.py#L364

以下是打印当前帐户使用信息的简短脚本:

import pprint
import shodan

key = 'YOUR API KEY'
api = shodan.Shodan(key)
results = api.info()
pprint.pprint(results)

shodan没有说明如何使用信息。下面是一个如何设置shodan信息的breif示例

import shodan
api = shodan.Shodan('YOUR API KEY')

info = api.host('8.8.8.8')
shodan info

相关问题 更多 >