Python Forum
Trying to use python-nmap but receiving however python2 or 3 can't find PortScanner.
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to use python-nmap but receiving however python2 or 3 can't find PortScanner.
#1
Hi All,

Given this code snippet, could you please help me understand what am I missing?

High level overview:

1) I've imported python-nmap
2) Imported using import nmap
3) Receiving AttributeError: 'function' object has no attribute 'PortScanner'

Details:

#!/bin/python

import sys
import getopt
import nmap

import xml.dom.minidom, xml.etree.ElementTree as et;

def nmap(vlan, netmask):
    # NMAP VLAN to determine IP availability.
    print ("NMAP Scanner")
    nm = nmap.PortScanner ()


def main():
    xmltree = et.parse(sys.argv[1]);

    # XML Tree Item = xti
    for xti in xmltree.iter('AR'):
        network_address = xti.find('NETWORK_ADDRESS').text;
        network_mask = xti.find('NETWORK_MASK').text;

        print ("[*] Network Address: ", network_address);
        print ("[*] Network Mask: ", network_mask);

    nmap(network_address, network_mask)

if __name__ == "__main__":
    main();
But instead, I'm getting:


Error:
[user@server01 nmap]$ ./get_address vlan2.xml ('[*] Network Address: ', '10.0.0.117') ('[*] Network Mask: ', '255.255.255.0') NMAP Scanner Traceback (most recent call last): File "./get_address", line 113, in <module> main(); File "./get_address", line 107, in main nmap(network_address, network_mask) File "./get_address", line 64, in nmap nm = nmap.PortScanner () AttributeError: 'function' object has no attribute 'PortScanner' [user@server01 nmap]$
I do have python-nmap installed:

[root@server01 nmap]# pip freeze|grep -Ei nmap
python-nmap==0.6.1
[root@server01 nmap]#

Since python2 is no longer supported, tried to use python3 but received the same error. My best interpretation of google search results is that python can't see the installed module. But I'm unable to get further then that.

Cheers,
TK
Reply


Messages In This Thread
Trying to use python-nmap but receiving however python2 or 3 can't find PortScanner. - by PythonNmap - Jan-19-2020, 12:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 2,464 Aug-13-2023, 12:16 AM
Last Post: cubangt
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 1,544 Jul-31-2022, 08:20 PM
Last Post: paulyan
  Receiving snmp traps with more than one Community String ilknurg 0 2,384 Jan-19-2022, 09:02 AM
Last Post: ilknurg
  [Selenium]Timed out receiving message from renderer: 10.000 wood_6636 0 2,751 Jun-26-2020, 08:59 AM
Last Post: wood_6636
  output mismatching when porting a python from python2 env to python3 env prayuktibid 2 2,704 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  Receiving XML exception from nmap.scan() results. PythonNmap 4 4,281 Jan-21-2020, 04:41 AM
Last Post: PythonNmap
  First Byte of a string is missing while receiving data over TCP Socket shahrukh1987 3 4,385 Nov-20-2019, 10:34 AM
Last Post: shahrukh1987
  Trying to run a python2 script dagamer1991 3 2,642 Aug-12-2019, 12:33 PM
Last Post: buran
  Use nmap inside my python code to get supported cipher suites jimmeh 4 5,406 May-30-2019, 01:07 PM
Last Post: jimmeh
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,841 May-20-2019, 11:24 AM
Last Post: vivekm

Forum Jump:

User Panel Messages

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