Python 2.7.12+ (default, Sep 1 2016, 20:27:38)
[GCC 6.2.0 20160822] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import nmap
import optparse
def nmapScan(tgtHost,tgtPort):
nmScan = nmap.PortScanner()
nmScan.scan(tgtHost,tgtPort)
state = nmScan[tgtHost][ 'tcp' ][ int (tgtPort)][ 'state' ]
print "[*] " + tgtHost + " tcp/" + tgtPort + " " + state
def main():
parser = optparse.OptionParser( 'usage %prog ' + \
'-H <target host> -p <target port>' )
parser.add_option( '-H' , dest = 'tgtHost' , type = 'string' ,\
help = 'specify target host' )
parser.add_option( '-p' , dest = 'tgtPort' , type = 'string' ,\
help = 'specify target port[s] separated by comma' )
(options, args) = parser.parse_args()
tgtHost = options.tgtHost
tgtPorts = str (options.tgtPort).split( ',' )
if (tgtHost = = None ) | (tgtPorts[ 0 ] = = None ):
print parser.usage
exit( 0 )
for tgtPort in tgtPorts:
nmapScan(tgtHost, tgtPort)
if __name__ = = '__main__' :
main()
|