Python中shodan模块的使用
2023-09-11 14:14:04 时间
关于shodan的安装和使用,传送门——> 渗透测试之Shodan的安装和使用
常用 Shodan 库函数
shodan.Shodan(key)
:初始化连接APIShodan.count(query, facets=None)
:返回查询结果数量Shodan.host(ip, history=False)
:返回一个IP的详细信息Shodan.ports()
:返回Shodan可查询的端口号Shodan.protocols()
:返回Shodan可查询的协议Shodan.services()
:返回Shodan可查询的服务Shodan.queries(page=1, sort='timestamp', order='desc')
:查询其他用户分享的查询规则Shodan.scan(ips, force=False)
:使用Shodan进行扫描,ips可以为字符或字典类型Shodan.search(query, page=1, limit=None, offset=None, facets=None, minify=True)
: 查询Shodan数据
先写一个简单的脚本,扫描 apache 的主机
import shodan #导入shodan库
api=shodan.Shodan("cB9sXwb7l95ZhSJaNgcaO7NQpkzfhQVM") #指定API_KEY,返回句柄
try:
results=api.search('apache') #搜索apache,返回 JSON格式的数据
print(results)
print("Results found:%s"%results['total'])
for result in results['matches']:
print(result['ip_str']) #打印出ip地址
except shoadn.APIError,e:
print("Error:%s"%e)
返回的JSON格式的数据
{
'total': 8669969,
'matches': [
{
'data': 'HTTP/1.0 200 OK\r\nDate: Mon, 08 Nov 2010 05:09:59 GMT\r\nSer...',
'hostnames': ['pl4t1n.de'],
'ip': 3579573318,
'ip_str': '89.110.147.239',
'os': 'FreeBSD 4.4',
'port': 80,
'timestamp': '2014-01-15T05:49:56.283713'
},
...
]
}
我们也可以加上端口号,并且写入文件中,作为访问链接
import shodan
api=shodan.Shodan("cB9sXwb7l95ZhSJaNgcaO7NQpkzfhQVM")
def FindTarget():
try:
f=open("target.txt","w")
results=api.search('JAWS/1.0')
print("Results found:%s"%results['total'])
for result in results['matches']:
url=result['ip_str']+":"+str(result['port'])
print(url)
f.write(url)
f.write("\n")
f.close()
except shodan.APIError,e:
print("Error:%s"%e)
FindTarget()
相关文章
- Python中zipfile压缩文件模块的使用
- Python中的random模块
- Python中os模块、csv模块和xlrd模块的使用
- python的multiprocessing模块进程创建、资源回收-Process,Pool
- 绘制渐变色扇形图 -基于python - matplotlib 颜色地图plt.cm模块儿
- python - 如何使用 Docker 运行多个 Python 脚本和一个可执行文件?
- python 模块
- Python traceback模块的使用(抛异常、报错、输出错误)
- python filecmp模块文件差异对比详解
- python re模块正则表达式详解
- net-snmp启用python模块
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【python】+704个常用工具Python库
- Python编程-基础知识-python项目包和文件的管理以及如何引用相对路径的包和模块
- python之模块py_compile用法(将py文件转换为pyc文件)
- python自动化运维常用模块安装
- 《Python高性能编程》——2.12 用dis模块检查CPython字节码
- python 模块的使用
- python 线性代数模块linalg
- 学习 Python 数学模块之 为什么我们需要使用数学模块
- python使用flask模块和前端交互基础
- PySerial-对测试人有帮助的Python串口开发模块
- 在安装了pyenv的macos上使用python turtle模块
- python基础之range()函数和random模块
- 【Python】Python使用smtplib和email模块发送邮件
- Python 爬虫之urllib库,及urllib库的4个模块基本使用和了解