Advertisement
rfmonk

pynmapscan.py

Nov 23rd, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import nmap
  4. import optparse
  5. def nmapScan(tgtHost, tgtPort):
  6.     nmScan = nmap.PortScanner()
  7.     nmScan.scan(tgtHost, tgtPort)
  8.     state=nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
  9.     print "[*] " + tgtHost + " tcp/"+tgtPort +" "+state
  10. def main():
  11.     parser = optparse.OptionParser('usage%prog '+\
  12.         ' -H <target host>')
  13.     parser.add_option('-H', dest='tgtHost', type='string', \
  14.         help='specify target host')
  15.     parser.add_option('-p', dest='tgtPort', type='string', \
  16.         help='specify target port[s] seperated by comma')
  17.     (options, args) = parser.parse_args()
  18.     tgtHost = options.tgtHost
  19.     tgtPorts = str(options.tgtPort).split(', ')
  20.     if (tgtHost == None) | (tgtPorts[0] == None):
  21.         print parser.usage
  22.         exit(0)
  23.     for tgtPort in tgtPorts:
  24.         nmapScan(tgtHost, tgtPort)
  25. if __name__ == '__main__':
  26.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement