Basic usage of Nmap's library under Python

Source: Internet
Author: User

ImportNmap#Import nmap.py ModuleNM = Nmap. Portscanner ()#instantiation of Nmap. Portscanner ObjectNm.scan ('127.0.0.1','22-443')#Scan 127.0.0.1, port number from 22 to 443Nm.command_line ()#gets the command line that currently performs the scan: Nmap-ox-P 22-443 127.0.0.1Nm.scaninfo ()#get Nmap Scan information {' TCP ': {' services ': ' 22-443 ', ' method ': ' Connect '}}Nm.all_hosts ()#get all the hosts that have been scannednm['127.0.0.1'].hostname ()#gets the host name of a host 127.0.0.1, typically a user recordnm['127.0.0.1'].hostnames ()#Gets the host list of host 127.0.0.1, returning a dictionary type#[{' Name ': ' hostname1 ', ' type ': ' PTR '}, {' name ': ' hostname2 ', ' type ': ' User '}]nm['127.0.0.1'].state ()#get the status of host 127.0.0.1 (up|down|unknown|skipped)nm['127.0.0.1'].all_protocols ()#gets the executed protocol [' TCP ', ' UDP '] contains (IP|TCP|UDP|SCTP)nm['127.0.0.1']['TCP'].keys ()#get all the port numbers for the TCP protocolnm['127.0.0.1'].ALL_TCP ()#get all port numbers for the TCP protocol (sort by port number size)nm['127.0.0.1'].ALL_UDP ()#get all the port numbers for the UDP protocol (sort by port number size)nm['127.0.0.1'].ALL_SCTP ()#get all port numbers for the SCTP protocol (sort by port number size)nm['127.0.0.1'].has_tcp (22)#host 127.0.0.1 Whether there is any information about Port 22nm['127.0.0.1']['TCP'][22]#Get host 127.0.0.1 information about Port 22nm['127.0.0.1'].tcp (22)#Get host 127.0.0.1 information about Port 22nm['127.0.0.1']['TCP'][22][' State']#get the status of host 22 ports (open)

Basic usage of Nmap's library under Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.