You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiaCTFer/client/portscan/ShodanScan.py

39 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import shodan
import time
from client.subdomain.oneforall.config import PortScan
check = True
if not PortScan.shodan_api:
print('[-]端口扫描-未填写shodan api秘钥')
check = False
else:
API = shodan.Shodan(PortScan.shodan_api)
try:
time.sleep(1)
API.info()
except shodan.exception.APIError as e:
print(f'[-]端口扫描-shodan api秘钥错误:{e}')
check = False
except Exception as e:
print(f'[-]端口扫描-shodan api接口异常{e}')
check = False
def Scan(ip):
print(f'[+]端口扫描-开始shodan端口扫描')
try:
ipinfo = API.host(ip)
except Exception as e:
print(f'[-]端口扫描-shodan查询{ip}失败,原因:{e}')
return None, None
port_list = ipinfo.get('ports', None)
vulns_list = ipinfo.get('vulns', None)
if port_list:
print(f'[+]端口扫描-shodan端口扫描[{ip}]完成:{port_list}')
return port_list, vulns_list
else:
return None, None
if __name__ == '__main__':
port_list, vulns_list = Scan('123.147.194.210')
print(port_list, vulns_list)