Python – nmap records


Python-nmap scan parameters:

Stage 1 – Design first, scan alive, get the target port again and start the service. (The first step to implement the function)

Installation module:

pip3  install  python-nmap
python3 -m pip install python-nmap
Copy the code

Common scanning methods:

Please go to: blog.csdn.net/qq\_3611919…

Come out alive:

Import nmap nm = nmap.portscanner () nm.scan('192.168.0.0/24', '80, Nm. scan(hosts='192.168.0.0/24', arguments=' -n-sp-pe-pa21,23,80,3389')Copy the code

The above is the parameter form for the relevant call to the reference document:

A lot of information is returned. What I want to obtain is the survival information of IP detected by the system:

Capture the IP value of the scanned information:

#! /usr/bin/python3 #_*_ encoding= UTF-8 _*_ import nmap import click @click.option('-ip', Default ='127.0.0.1/24', help='Input you IP.', type= STR) def Alive(IP): Nm = nmap.portscanner () data = nm.scan(hosts= IP, arguments=' -sp ') for IP in data['scan']. Keys (): print(' IP live: '+ip) if __name__ == '__main__': Alive()Copy the code

Grab the information you want

Write the surviving IP to TXT

For ips in data['scan'].keys(): print(' ips: '+ips) with open(file_name, 'a+', encoding=' utF-8 ') as aliveip: aliveip.write(ips + "\n")Copy the code

The main analysis is to obtain the original inside the packet

Got CSND to test it out

Test access port, port service status, open status.

Live IP addresses are stored in ip.txt, while open ports are stored in port.txt

At the same time, test the IP and C segment to obtain the situation, feel good.

Start function implementation. Do other modules later

Reference:

Blog.csdn.net/qq\_3611919…

www.cnblogs.com/zhangjiangh…

Disclaimer: This site provides safety tools, procedures (methods) may be offensive, only for safety research and teaching, risk!

Subscribe for more revisited articles and study notes

thelostworld

Safe road, side by side with you !!!!

Personal knowledge: www.zhihu.com/people/fu-w…

Brief personal book: www.jianshu.com/u/bf0e38a8d…