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

VC 6.0 挂服务 提示503

我们有一台VC 6.0的服务挂…

3 周 ago

零成本grass挖矿教程

最近发现个新币,还没上交易所,…

4 周 ago

Windows Server 2025 的AD架构版本

   Windows 2025…

4 周 ago

【项目】跨数据中心(跨站点)Exchange Server 2013恢复/高可用

今年换到一家乙方公司了,主要工…

1 月 ago

主域挂了怎么办?

假设在极端情况下,没有备份的前…

1 月 ago

为什么在AD管理中只能看到3个操作主机?

我们在日常的Windows域管…

1 月 ago