shodan国家代码python

2024-05-20 17:22:08 发布

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

我想在python中列出一次我的脚本搜索特定的字符串,但是我还想添加国家代码的前两个字母,但是当我尝试时,它会显示invalid KeyError:“country_code”,但是api显示位置国家代码我怎么才能做到呢?在

 #!/usr/bin/python
import shodan
SHODAN_API_KEY="xxxxxxxxxxxxxxxxxxxx"
api = shodan.Shodan(SHODAN_API_KEY)

try:
    # Search Shodan
    results = api.search('ProFTPd-1.3.3c')

    # Show the results
    for result in results['matches']:
        print '%s' % result['ip_str']
        print '%s' % result['country_code']

except shodan.APIError, e:
        print 'Error: %s' % e

Tags: key字符串代码脚本apicoderesult国家
1条回答
网友
1楼 · 发布于 2024-05-20 17:22:08

我想这就是您在Python中使用的方法 https://github.com/achillean/shodan-python/blob/master/shodan/client.py#L324 它会触发:

return self._request('/shodan/host/search', args)

Shodan API文档: https://developer.shodan.io/api 查看/shodan/host/searchAPI

我刚看到答案在你的问题,但你吃了一封来自地点的信。在

试试这个:

^{pr2}$

所以你们要找的字段在那个里,但它在另一本字典里。在

我建议下次仔细阅读API文档,正如Nofal Daud所说,Python错误是不言而喻的,如果dict上有keyror,就意味着字段不存在。下一次听Python,它将揭示真相。在

相关问题 更多 >