Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nmap
#1
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()
Reply
#2
on line 17 looks like you overwrite tgtPort which was set in line 15
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to Scan multiple IPs with python-nmap DarkSuniuM 5 9,488 Apr-09-2017, 06:34 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020