nmap - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: nmap (/thread-27378.html) |
nmap - sagpal - Jun-04-2020 hi, can someone help me with this error. import nmap import optparse def nampScan(tgtHost, tgtPort): nmScan = nmap.PortScanner() nmScan.scan(tgtHost, tgtPort) state = nmScan[tgtPort]['tcp'][int(tgtHost)]['state'] print("[*]" + tgtHost + "tcp/" + tgtPort + " " + state) def main(): parser = optparse.OptionParser('usage%prog ' + '-H <target host> -p <target port>') parser.add_option('-H', dest='tgtPort', 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 (tgtPorts == None) | (tgtPorts[0] == None): print(parser.usage) exit(0) for tgtPort in tgtPorts: nampScan(tgtPorts, tgtPort) if __name__ == '__main__': main()
RE: nmap - Larz60+ - Jun-04-2020 on line 17 looks like you overwrite tgtPort which was set in line 15 RE: nmap - sagpal - Jun-04-2020 Larz60+ you are right, i corrected the line 15 & 17. here is the attributeError. thanks for you help.
|