11# Script Name : nmap_scan.py
22# Author : Craig Richards
33# Created : 24th May 2013
4- # Last Modified :
4+ # Last Modified :
55# Version : 1.0
66
7- # Modifications :
7+ # Modifications :
88
99# Description : This scans my scripts directory and gives a count of the different types of scripts, you need nmap installed to run this
1010
1111import nmap # Import the module
1212import optparse # Import the module
1313
14- def nmapScan (tgtHost , tgtPort ): # Create the function, this fucntion does the scanning
15- nmScan = nmap .PortScanner ()
16- nmScan .scan (tgtHost , tgtPort )
17- state = nmScan [tgtHost ]['tcp' ][int (tgtPort )]['state' ]
18- print "[*] " + tgtHost + " tcp/" + tgtPort + " " + state
19-
14+
15+ def nmapScan (tgtHost , tgtPort ): # Create the function, this fucntion does the scanning
16+ nmScan = nmap .PortScanner ()
17+ nmScan .scan (tgtHost , tgtPort )
18+ state = nmScan [tgtHost ]['tcp' ][int (tgtPort )]['state' ]
19+ print "[*] " + tgtHost + " tcp/" + tgtPort + " " + state
20+
21+
2022def main (): # Main Program
2123 parser = optparse .OptionParser ('usage%prog ' + '-H <host> -p <port>' ) # Display options/help if required
2224 parser .add_option ('-H' , dest = 'tgtHost' , type = 'string' , help = 'specify host' )
2325 parser .add_option ('-p' , dest = 'tgtPort' , type = 'string' , help = 'port' )
2426 (options , args ) = parser .parse_args ()
2527 tgtHost = options .tgtHost
2628 tgtPorts = str (options .tgtPort ).split (',' )
27-
28- if (tgtHost == None ) | (tgtPorts [0 ] == None ):
29+
30+ if (tgtHost == None ) | (tgtPorts [0 ] == None ):
2931 print parser .usage
30- exit (0 )
31-
32- for tgtPort in tgtPorts : # Scan the hosts with the ports etc
32+ exit (0 )
33+
34+ for tgtPort in tgtPorts : # Scan the hosts with the ports etc
3335 nmapScan (tgtHost , tgtPort )
3436
37+
3538if __name__ == '__main__' :
36- main ()
39+ main ()
0 commit comments