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.
#15
(Jan-19-2020, 04:11 PM)buran Wrote: Hm. that is strange
you have python-nmap installed for both python2 and python3

so, you shoould have also /usr/local/lib/python3.6/site-packages/nmap/nmap.py file
the __init__.py you show imports everything from it, incl PortScanner.

Yep, the above file exists.
$ ls -altri /usr/local/lib/python3.6/site-packages/nmap/nmap.py
803233 -rw-r--r--. 1 root root 687 Jan 17 09:38 /usr/local/lib/python3.6/site-packages/nmap/nmap.py
(Jan-19-2020, 04:11 PM)buran Wrote: Can you check that that file is there and also __init__.py file has from .nmap import * line?
$ cat __init__.py
from .nmap import nmap

Ya, looks good:

[user@server01 nmap]$ cat __init__.py
from .nmap import nmap
[user@server01 nmap]$ pwd
/usr/local/lib/python3.6/site-packages/nmap
[user@server01 nmap]$

(Jan-19-2020, 04:11 PM)buran Wrote: you can have a look at the package structure in the source https://xael.org/pages/python-nmap-0.6.1.tar.gz or in the repo https://bitbucket.org/xael/python-nmap/src/default/

As to the error you get in python2 - python-nmap package is wrapper that makes easy to automate running nmap port scanner - https://nmap.org/

i.e. as far as I understand it - you need to install nmap port scanner utility separately

Ya, I see nmap is missing from my system. That's an easy fix I'll do now.

I thought I did install it separately. When you say 'separately', what do you consider 'separately'?

Tried to install python3-nmap, since python3 is the future:

pip search nmap
python3-nmap (1.3.1)     - Python3-nmap converts Nmap commands into python3 methods making it very easy to use nmap in any of your python pentesting projects

pip install python3-nmap
ERROR: Could not find a version that satisfies the requirement python3-nmap (from versions: none)
ERROR: No matching distribution found for python3-nmap
Though it comes up in search, it fails to install. When I switch the interpreter to python3, since I would like to use the latest supported version, I get the original error:

[user@server01 ipa-nmap]$  ./ip-get.py vlan2.xml
/usr/local/lib/python3.6/site-packages/nmap/__init__.py
/usr/local/lib/python3.6/site-packages/nmap/__init__.py
[*] Network Address:  10.0.0.117
[*] Network Mask:  255.255.255.0
NMAP Scanner
Traceback (most recent call last):
  File "./ip-get.py", line 34, in <module>
    main();
  File "./ip-get.py", line 31, in main
    nmapScan(network_address, network_mask)
  File "./ip-get.py", line 17, in nmapScan
    nm = nmap.PortScanner ()
AttributeError: module 'nmap' has no attribute 'PortScanner'
[user@server01 ipa-nmap]$
[user@server01 ipa-nmap]$
[user@server01 ipa-nmap]$
[user@server01 ipa-nmap]$ cat /usr/local/lib/python3.6/site-packages/nmap/__init__.py
from .nmap import nmap
[user@server01 ipa-nmap]$
[user@server01 ipa-nmap]$
[user@server01 ipa-nmap]$ ls -altri /usr/local/lib/python3.6/site-packages/nmap/
total 12
   803233 -rw-r--r--.  1 root root  687 Jan 17 09:38 nmap.py
   803232 -rw-r--r--.  1 root root   23 Jan 17 09:38 __init__.py
   803231 drwxr-xr-x.  3 root root   56 Jan 17 09:38 .
 67689421 drwxr-xr-x.  2 root root   62 Jan 17 09:38 __pycache__
135679242 drwxr-xr-x. 45 root root 4096 Jan 17 09:38 ..
[user@server01 ipa-nmap]$
Thx,
TK
Reply


Messages In This Thread
RE: Trying to use python-nmap but receiving however python2 or 3 can't find PortScanner. - by PythonNmap - Jan-19-2020, 06:54 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,278 Aug-13-2023, 12:16 AM
Last Post: cubangt
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 1,503 Jul-31-2022, 08:20 PM
Last Post: paulyan
  Receiving snmp traps with more than one Community String ilknurg 0 2,303 Jan-19-2022, 09:02 AM
Last Post: ilknurg
  [Selenium]Timed out receiving message from renderer: 10.000 wood_6636 0 2,695 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,646 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  Receiving XML exception from nmap.scan() results. PythonNmap 4 4,196 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,322 Nov-20-2019, 10:34 AM
Last Post: shahrukh1987
  Trying to run a python2 script dagamer1991 3 2,596 Aug-12-2019, 12:33 PM
Last Post: buran
  Use nmap inside my python code to get supported cipher suites jimmeh 4 5,321 May-30-2019, 01:07 PM
Last Post: jimmeh
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,802 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