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

Share
Published by
Kai

Recent Posts

SoalrWinds 2025.1

 发行说明:https://d…

3 天 ago

诺顿360 豪华版免费升级到诺顿360专业版

还是用诺顿360 60天 OE…

4 天 ago

链接到京东技术交流群

 链接到京东技术交流群

1 周 ago

【PDF】京东基础架构建设之路

 邮箱:gyd1#vip.qq…

1 周 ago

【PDF】京东数据中心构建实战

 邮箱:gyd1#vip.qq…

1 周 ago