1 Star 0 Fork 46

梁忠云/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.02.29 python-nmap ping扫描 1001 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-02-29 09:18 . new file
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import nmap
import sys
def nmap_ping_scan(network_prefix):
nm = nmap.PortScanner()
ping_scan_raw_result = nm.scan(hosts=network_prefix, arguments='-v -n -sn')
host_list = []
for IP in ping_scan_raw_result['scan']:
if ping_scan_raw_result['scan'][IP]['status']['state'] == 'up':
host_list.append(ping_scan_raw_result['scan'][IP]['addresses']['ipv4'])
#print( '%-20s %5s' % (ping_scan_raw_result['scan'][IP]['addresses']['ipv4'],'is UP'))
return host_list
if __name__ == '__main__':
for host in nmap_ping_scan(sys.argv[1]):
print( '%-20s %5s' % (host,'is UP'))
#################################################################
#[root@Fedora python]# ./nmap_ping_scan.py 172.16.1.0/24
#172.16.1.104 is UP
#172.16.1.101 is UP
#172.16.1.103 is UP
#172.16.1.102 is UP
#172.16.1.107 is UP
#172.16.1.254 is UP
#172.16.1.15 is UP
#172.16.1.12 is UP
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/liangzhongyun/qytang_Python.git
git@gitee.com:liangzhongyun/qytang_Python.git
liangzhongyun
qytang_Python
qytang_Python
master

搜索帮助