python 使用nmap 模块

官网 https://pypi.org/project/python-nmap/

>>> import nmap
>>> nm = nmap.PortScannerScanner()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module ‘nmap‘ has no attribute ‘PortScannerScanner‘
>>> nm = nmap.PortScanner()
>>> nm.scan(‘127.0.0.1‘,‘22-443‘)
{‘nmap‘: {‘command_line‘: ‘nmap -oX - -p 22-443 -sV 127.0.0.1‘, ‘scaninfo‘: {‘tcp‘: {‘method‘: ‘syn‘, ‘services‘: ‘22-443‘}}, ‘scanstats‘: {‘timestr‘: ‘Wed Oct 23 17:25:01 2019‘, ‘elapsed‘: ‘6.20‘, ‘uphosts‘: ‘1‘, ‘downhosts‘: ‘0‘, ‘totalhosts‘: ‘1‘}}, ‘scan‘: {‘127.0.0.1‘: {‘hostnames‘: [{‘name‘: ‘localhost‘, ‘type‘: ‘PTR‘}], ‘addresses‘: {‘ipv4‘: ‘127.0.0.1‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘localhost-response‘}, ‘tcp‘: {22: {‘state‘: ‘open‘, ‘reason‘: ‘syn-ack‘, ‘name‘: ‘ssh‘, ‘product‘: ‘OpenSSH‘, ‘version‘: ‘7.4‘, ‘extrainfo‘: ‘protocol 2.0‘, ‘conf‘: ‘10‘, ‘cpe‘: ‘cpe:/a:openbsd:openssh:7.4‘}, 25: {‘state‘: ‘open‘, ‘reason‘: ‘syn-ack‘, ‘name‘: ‘smtp‘, ‘product‘: ‘Postfix smtpd‘, ‘version‘: ‘‘, ‘extrainfo‘: ‘‘, ‘conf‘: ‘10‘, ‘cpe‘: ‘cpe:/a:postfix:postfix‘}, 111: {‘state‘: ‘open‘, ‘reason‘: ‘syn-ack‘, ‘name‘: ‘rpcbind‘, ‘product‘: ‘‘, ‘version‘: ‘2-4‘, ‘extrainfo‘: ‘RPC #100000‘, ‘conf‘: ‘10‘, ‘cpe‘: ‘‘}}}}}
>>> nm.command_line
<bound method PortScanner.command_line of <nmap.nmap.PortScanner object at 0x2ba54ca28978>>
>>> nm.command_line()
‘nmap -oX - -p 22-443 -sV 127.0.0.1‘
>>> nm.scaninfo
<bound method PortScanner.scaninfo of <nmap.nmap.PortScanner object at 0x2ba54ca28978>>
>>> nm.scaninfo()
{‘tcp‘: {‘method‘: ‘syn‘, ‘services‘: ‘22-443‘}}
>>> nm.scaninfo()[‘tcp‘]
{‘method‘: ‘syn‘, ‘services‘: ‘22-443‘}
>>> nm.scaninfo()[‘tcp‘][‘method‘]
‘syn‘
>>> nm.all_hosts()
[‘127.0.0.1‘]
>>> nm[‘127.0.0.1‘].hostname()
‘localhost‘
>>> nm[‘127.0.0.1‘].hostnames()
[{‘name‘: ‘localhost‘, ‘type‘: ‘PTR‘}]
>>> nm.scan(hosts="192.168.1.0/24",arguments="-n -sP -PE")
{‘nmap‘: {‘command_line‘: ‘nmap -oX - -n -sP -PE 192.168.1.0/24‘, ‘scaninfo‘: {}, ‘scanstats‘: {‘timestr‘: ‘Wed Oct 23 17:29:13 2019‘, ‘elapsed‘: ‘1.07‘, ‘uphosts‘: ‘15‘, ‘downhosts‘: ‘241‘, ‘totalhosts‘: ‘256‘}}, ‘scan‘: {‘192.168.1.1‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.1‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.43‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.43‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.50‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.50‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.72‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.72‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.74‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.74‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.77‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.77‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.80‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.80‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.103‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.103‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.203‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.203‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.204‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.204‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.211‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.211‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.222‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.222‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.243‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.243‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.245‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.245‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}, ‘192.168.1.255‘: {‘hostnames‘: [{‘name‘: ‘‘, ‘type‘: ‘‘}], ‘addresses‘: {‘ipv4‘: ‘192.168.1.255‘}, ‘vendor‘: {}, ‘status‘: {‘state‘: ‘up‘, ‘reason‘: ‘echo-reply‘}}}}
>>> nm.all_hosts()
[‘192.168.1.1‘, ‘192.168.1.103‘, ‘192.168.1.203‘, ‘192.168.1.204‘, ‘192.168.1.211‘, ‘192.168.1.222‘, ‘192.168.1.243‘, ‘192.168.1.245‘, ‘192.168.1.255‘, ‘192.168.1.43‘, ‘192.168.1.50‘, ‘192.168.1.72‘, ‘192.168.1.74‘, ‘192.168.1.77‘, ‘192.168.1.80‘]

原文地址:https://www.cnblogs.com/zoulixiang/p/11727633.html

时间: 2024-10-20 16:19:33

python 使用nmap 模块的相关文章

端口扫描器--利用python的nmap模块

安装nmap模块挺麻烦的,搞了半天 不仅要安装pip install nmap 还要sudo apt install nmap 给出代码,没有设多线程,有点慢,注意端口的类型转换,搞了很久 #!/usr/bin/env python # -*- coding:UTF-8 -*- import optparse import nmap #usage:python scan.py -H 119.75.217.26 -p 3306 80 22 def nampScan(tgtHost,tgPort):

使用python的nmap模块扫描主机生成csv文档

脚本如下,需要用到IPy模块,python-nmap模块,脚本执行后,以csv文档将结果输出到屏幕上 #!/usr/bin/env python3 ''' 参考链接 https://blog.csdn.net/qq_36119192/article/details/83717690 使用方法: nmap_scan.py 192.168.0.0/24 22,3389 支持单个IP,网段扫描 网段格式支持:192.168.0.0/24,192.168.0.0/24 需要扫描的端口用逗号分隔 '''

python(nmap模块、多线程模块)

http://xael.org/pages/python-nmap-en.html       nmap模块 http://www.tutorialspoint.com/python/python_multithreading.htm   多线程 http://www.cnblogs.com/tqsummer/archive/2011/01/25/1944771.html 多线程

python模块学习----nmap模块

安装nmap模块: pip install python_nma nmap模块说明: python-nmap是一个帮助使用nmap端口扫描器的python库.它允许轻松操纵nmap扫描结果,并且将是一个完美的选择,为需要自动完成扫描任务的系统管理员提供的工具并报告.它也支持nmap脚本输出. nmap模块类: ET:Python的轻量级XML支持 PortScanner:端口扫描 PortScannerAsync:异步进行端口扫描 PortScannerError:nmap的异常错误类 Port

7.安装pycharm----导入Nmap模块----netcat反向shell----metasploitable靶机环境

安装pycharm www.jetbrains.com/pycharm/ tar -zxvf p补全 ls cd p补全 ls cd bin ls ./pycharm.sh 新建项目 pythonRocks.py print "python Rocks" cd Desktop ls chmod +x pythonRocks.py ls python pythonRocks.py 导入Nmap模块 cd Desktop pip install python-nmap 从网站的方式下载模块

Python中subprocess 模块 创建并运行一个进程

python的subprocess模块,看到官方声明里说要尽力避免使用shell=True这个参数,于是测试了一下: from subprocess import call import shlex cmd = "cat test.txt; rm test.txt" call(cmd, shell=True) 运行之后: 1:打开并浏览了test.txt文件 2:删除了test.txt文件 from subprocess import call import shlex cmd = &

python时间处理模块 datetime time模块 deltetime模块

1 首先介绍time模块,因为简单 python 自带模块 本人使用time模块,只使用两个函数 time函数和sleep函数 import time a.     time.time()   函数 返回unix时间  常用作两个时间差的计算 b.     time.sleep()  休眠多久,精度为子秒(subsecond) In [90]: t1 = time.time() In [91]: t1 Out[91]: 1461400225.877932 In [92]: time.sleep(

python安装mysqldb模块

今天在阿里云一台新的服务器部署程序后台,发现上面的python缺少MySQLDB 模块,记录安装过程. 首先django程序,运行 python manage.py sycdb 报错: ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb MySQLdb模块的包名字叫mysql-python,于是pip安装之,(关于pip,可以参考这篇文章) 运行: pip install mysql-python

Python 利用pytesser模块识别图像文字

使用的是python的pytesser模块,原先想做的是图片中文识别,搞了一段时间了,在中文的识别上还是有很多问题,这里做记录分享. pytesser,OCR in Python using the Tesseract engine from Google.是谷歌OCR开源项目的一个模块,可将图片中的文字转换成文本(主要是英文). 1.pytesser安装 使用设备:win8 64位 PyTesser使用Tesseract OCR引擎,将图像转换到可接受的格式,然后执行tesseract提取出文