Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
Created November 16, 2012 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mike-zhang/4084385 to your computer and use it in GitHub Desktop.
Save mike-zhang/4084385 to your computer and use it in GitHub Desktop.
udp端口扫描(python-nmap代码)
#! /usr/bin/python
import nmap
# python-nmap url : http://xael.org/norman/python/python-nmap/python-nmap-0.1.4.tar.gz
nm = nmap.PortScanner()
nm.scan(hosts='192.168.1.0/24', arguments='-n -p 161 -sU ')
hosts_list = [(x, nm[x][u'udp'][161]['state']) for x in nm.all_hosts()]
#print nm.all_hosts()
#print nm[u'192.168.1.100'][u'udp'][161]['state']
for host, status in hosts_list:
print('{0}:{1}'.format(host, status))
@mike-zhang
Copy link
Author

这个依赖nmap程序,底层是调用shell下的nmap实现的:

launch 'nmap -V', we wait after 'Nmap version 5.0 ( http://nmap.org )'

p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
self._nmap_last_output = p.communicate()[0] # store stdout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment