Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the nmap module of python to scan the host to generate csv documents

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

The script is as follows. You need to use IPy module and python-nmap module. After the script is executed, output the result to the screen in a csv document.

#! / usr/bin/env python3''' reference link https://blog.csdn.net/qq_36119192/article/details/83717690 usage: nmap_scan.py 192.168.0.0Universe 24 22Magi 3389 supports a single IP, network segment scanning format supports: 192.168.0.0Universe 24 192.168.0.024 the ports to be scanned are separated by commas using grep filter results grep-E'22 | 3389''''import sysimport nmapfrom IPy import IPif len (sys.argv)! = 3: print ("Parameter error, supported format: single IP Network segment in suffix or mask form ") exit (1) scan_ip = IP (sys.argv [1]) scan_port = sys.argv [2] # scan_ip.prefixlen () # transfer the network segment to the suffix form scan_ip =" {} ".format (scan_ip) for port in [int (I) for i in scan_port.split (", ")]: if port

< 1 or port >

65535: print ("Port range 1-65535") exit (1) nm=nmap.PortScanner () nm.scan (scan_ip, scan_port,'-Pn') hosts = nm.all_hosts () for host in hosts: mac = nm [host] ["addresses"] .get ("mac") ") tcp = nm [host] [" tcp "] ports = nm [host] [" tcp "] .keys () ports_list = [] # ports_list_len = 0 for port in ports: if tcp [port] [" state "] = =" open ": ports_list.append (" {} ".format (port)) # ports_list_len + = 1 else: ports_list.append ("") # if ports_list_len! = 0 print # print ("{}) {}, {} ".format (host, mac,", ".join (ports_list)) print (" {}, {}, {} ".format (host, mac,", ".join (ports_list)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report