This is the script
import nmap
import optparsedef nmapScan(tgtHost,tgtPort):nmScan = nmap.PortScanner()nmScan.scan(tgtHost,tgtPort)state=nmScan[tgtHost]['tcp'][int(tgtPort)]['state']print "[*] " + tgtHost + " tcp/"+tgtPort +" "+statedef main():parser = optparse.OptionParser('-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.tgtHosttgtPorts = str(options.tgtPort).split(',')if (tgtHost == None) | (tgtPorts[0] == None):print parser.usageexit(0)for tgtPort in tgtPorts:nmapScan(tgtHost, tgtPort)if __name__ == '__main__':main()
When I try to enter a range of ports in the command line, I get this error. Could someone help me out? I'm a newbie to python. Thanks in advance!!
:~$ python nmapScan.py -H 192.168.1.6 -p 20-25
Traceback (most recent call last):File "nmapScan.py", line 27, in <module>main()File "nmapScan.py", line 23, in mainnmapScan(tgtHost, tgtPort)File "nmapScan.py", line 7, in nmapScanstate=nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
ValueError: invalid literal for int() with base 10: '20-25'