这是我的代码:
我导入模块
import shodan
import json
我创造我的钥匙,
SHODAN_API_KEY = ('xxxxxxxxxxxxxxxxxxxx')
api = shodan.Shodan(SHODAN_API_KEY)
我打开我的 json 文件,
with open('Ports.json', 'r') as f:
Ports_dict = json.load(f)
我遍历我的字典,
for Port in Ports_dict:
print(Port['Port_name'])
try:
results = api.search(Port['Port_name']) # how can I filter ports by country??
我打印内容。
print('Results found: {}'.format(results['total']))
for result in results['matches']:
print('IP: {}'.format(result['ip_str']))
print(result['data'])
print('')
print ('Country_code: %s' % result['location']['country_code'])
except shodan.APIError as e:
print(' Error: %s' % e)
但是如何按国家/地区过滤端口?