Categories: python工作

使用nmap来扫描局域网内的主机

环境mac

 

pip3 install python-nmap     #先安装

导入包

import nmap

nm = nmap.PortScanner()

nm.scan(hosts='10.12.11.67/24',arguments='-n -sP -PE')

 

结果

{'nmap': {'command_line': 'nmap -oX - -n -sP -PE 10.12.11.0/24',

  'scaninfo': {'warning': ['Warning:  You are not root -- using TCP pingscan rather than ICMP\n']},

  'scanstats': {'downhosts': '254',

   'elapsed': '6.64',

   'timestr': 'Tue Mar 27 04:13:39 2018',

   'totalhosts': '256',

   'uphosts': '2'}},

'scan': {'10.12.11.50': {'addresses': {'ipv4': '10.12.11.50'},

   'hostnames': [{'name': '', 'type': ''}],

   'status': {'reason': 'syn-ack', 'state': 'up'},

   'vendor': {}},

  '10.12.11.67': {'addresses': {'ipv4': '10.12.11.67'},

   'hostnames': [{'name': '', 'type': ''}],

   'status': {'reason': 'conn-refused', 'state': 'up'},

   'vendor': {}}}}

 

nm.all_hosts()

['10.12.11.50', '10.12.11.67']

 

 

host是网段

arguments是参数。

-n只扫描IP,不扫描解析。

-sP扫描一次,提高效率

-PE扫描服务端口

nm.all_hosts()返回扫描到的主机IP

Kai

Recent Posts

ESXi精简置备盘空间回收

   家里的nuc上lab环境…

2 月 ago

Dell MD系列存储重置管理密码

正好手里有几台Dell MD3…

2 月 ago

Dell ME4存储管理口无法登录修复

这次碰到一台DELL ME40…

2 月 ago

分享个便宜速度快的云主机

野草云 https://my.…

3 月 ago

众筹微软大佬徐庭老师M365课程

 联系邮箱:gyd1#vip.…

4 月 ago

MySQL EOL和版本推荐

   MySQL 5.7版本已…

4 月 ago