1
+ # Script Name : nmap_scan.py
2
+ # Author : Craig Richards
3
+ # Created : 24th May 2013
4
+ # Last Modified :
5
+ # Version : 1.0
6
+
7
+ # Modifications :
8
+
9
+ # Description : This scans my scripts directory and gives a count of the different types of scripts, you need nmap installed to run this
10
+
11
+ import nmap # Import the module
12
+ import optparse # Import the module
13
+
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
+
20
+ def main (): # Main Program
21
+ parser = optparse .OptionParser ('usage%prog ' + '-H <host> -p <port>' ) # Display options/help if required
22
+ parser .add_option ('-H' , dest = 'tgtHost' , type = 'string' , help = 'specify host' )
23
+ parser .add_option ('-p' , dest = 'tgtPort' , type = 'string' , help = 'port' )
24
+ (options , args ) = parser .parse_args ()
25
+ tgtHost = options .tgtHost
26
+ tgtPorts = str (options .tgtPort ).split (',' )
27
+
28
+ if (tgtHost == None ) | (tgtPorts [0 ] == None ):
29
+ print parser .usage
30
+ exit (0 )
31
+
32
+ for tgtPort in tgtPorts : # Scan the hosts with the ports etc
33
+ nmapScan (tgtHost , tgtPort )
34
+
35
+ if __name__ == '__main__' :
36
+ main ()
0 commit comments