On 2022-05-19 20:28, ^Bart wrote:
You forgot the second line (after 'import nmap' and before 'nm.scan()'):

     nm = nmap.PortScanner()

import nmap
nm = nmap.PortScanner()
nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
for host, status in hosts_list:
       print('{0}:{1}'.host)

And the result is:

Traceback (most recent call last):
    File "/home/gabriele/Documenti/Python/nmap.py", line 1, in <module>
      import nmap
    File "/home/gabriele/Documenti/Python/nmap.py", line 2, in <module>
      nm = nmap.PortScanner()
AttributeError: partially initialized module 'nmap' has no attribute
'PortScanner' (most likely due to a circular import)
  >>>

I'm using the IDLE Shell 3.9.2 on Debian Bullseye+KDE, if I write the
script from command line it works!

When you installed nmap it would've been installed into site-packages, but the traceback says "/home/gabriele/Documenti/Python/nmap.py", which suggests to me that you called your script "nmap.py", so it's shadowing what you installed and is actually trying to import itself!
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to