Python Forum
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()
Error:
Exception has occurred: AttributeError 'Values' object has no attribute 'tgtHost' File "D:\py\nmap.py", line 20, in main tgtHost = options.tgtHost File "D:\py\nmap.py", line 31, in <module> 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.

Error:
Exception has occurred: AttributeError 'Values' object has no attribute 'tgtHost' File "D:\Skill\python\py\nmap.py", line 20, in main tgtHost = options.tgtHost File "D:\Skill\python\py\nmap.py", line 31, in <module> main()