python nmap模块详解_python 使用nmap 模块

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

>>> import nmap

>>> nm = nmap.PortScannerScanner()

Traceback (most recent call last):

File "", line 1, in

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

>

>>> nm.command_line()

'nmap -oX - -p 22-443 -sV 127.0.0.1'

>>> nm.scaninfo

>

>>> 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']

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值