1
1
# Script Name : nmap_scan.py
2
2
# Author : Craig Richards
3
3
# Created : 24th May 2013
4
- # Last Modified :
4
+ # Last Modified :
5
5
# Version : 1.0
6
6
7
- # Modifications :
7
+ # Modifications :
8
8
9
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
10
11
11
import nmap # Import the module
12
12
import optparse # Import the module
13
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
-
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
+
20
22
def main (): # Main Program
21
23
parser = optparse .OptionParser ('usage%prog ' + '-H <host> -p <port>' ) # Display options/help if required
22
24
parser .add_option ('-H' , dest = 'tgtHost' , type = 'string' , help = 'specify host' )
23
25
parser .add_option ('-p' , dest = 'tgtPort' , type = 'string' , help = 'port' )
24
26
(options , args ) = parser .parse_args ()
25
27
tgtHost = options .tgtHost
26
28
tgtPorts = str (options .tgtPort ).split (',' )
27
-
28
- if (tgtHost == None ) | (tgtPorts [0 ] == None ):
29
+
30
+ if (tgtHost == None ) | (tgtPorts [0 ] == None ):
29
31
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
33
35
nmapScan (tgtHost , tgtPort )
34
36
37
+
35
38
if __name__ == '__main__' :
36
- main ()
39
+ main ()
0 commit comments