首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shodan -乡村代码python

shodan -乡村代码python
EN

Stack Overflow用户
提问于 2018-02-17 19:06:39
回答 1查看 1.2K关注 0票数 0

我想列出一次我的脚本在python中搜索特定的字符串,但我也想添加国家代码的前两个字母,但当我尝试然后它说无效的KeyError:' country _ code ',但是api说我如何实现ocation.country_code?

代码语言:javascript
复制
 #!/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
EN

回答 1

Stack Overflow用户

发布于 2018-02-17 19:34:42

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

代码语言:javascript
复制
return self._request('/shodan/host/search', args)

Shodan文档:/shodan/host/search https://developer.shodan.io/api签出

我刚看到答案在你的问题上,但你吃了一封来自位置(定位)的信。

试试这个:

代码语言:javascript
复制
print '%s' % result['location']['country_code']

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

我建议下次很好地阅读API文档,就像Nofal所说的那样,Python错误是不言自明的--如果您有dict上的KeyError --这意味着字段不存在。下一次听Python,它将揭示真相。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48844919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档