Python Forum
Trying to Scan multiple IPs with python-nmap
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to Scan multiple IPs with python-nmap
#1
Hello
Im new to this forum and I don't know if I posted this thred on right forum.
Here is my problem:
Im trying to scan multiple IPs with python-nmap but It returns an error: 

Error:
    assert type(hosts) is str, 'Wrong type for [hosts], should be a string [was {0}]'.format(type(hosts))  # noqa AssertionError: Wrong type for [hosts], should be a string [was <class 'list'>]
Error related to this part:
ns.scan(['192.168.1.1', '4.2.2.4'], port_input, '-sV')
Help me if u can <3 thanks

And Sry for bad English
Reply
#2
It is in the error message.

scan() requires a string for the hosts not a list.
Try:
ns.scan("192.168.1.1 4.2.2.4", port_input, '-sV')
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Apr-07-2017, 12:01 PM)wavic Wrote: It is in the error message.

scan() requires a string for the hosts not a list.
Try:
ns.scan("192.168.1.1 4.2.2.4", port_input, '-sV')

Hello wavic, Thanks for your reply.
I understood error but the question is How can I fix it ?
Reply
#4
Did you try what I suggested?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
(Apr-08-2017, 04:01 PM)wavic Wrote: Did you try what I suggested?

I fixed it by this code:
ns.scan(hosts=ip_input, arguments='-n -sP -PE -PA%s' % port_input)
Now I want to print some results like this:
192.168.1.1 => 80 Open
192.168.1.1 => 143 Open
192.168.1.33 => 22 Open
...

Can you help me with this ?
Reply
#6
After your scan:

for host in np.all_hosts():
    for port in np[host].all_tcp():
        print("{} => {:<5} {}".format(host, port, np[host]['tcp'][port]['state']))
Output:
127.0.0.1 => 4433  open 127.0.0.1 => 4434  open
Here I am scaning ports 22 to 5000

If that is what you want.

n.scan() returns a dictionary with all info within. If you pprint.pprint() it, you will see how to get all you need.
Sorry for the delay but I am not aware with this module.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  scapy wifi scan to get payload \ data korenron 0 2,109 Nov-16-2021, 01:47 PM
Last Post: korenron
  can I set scan interval for scapy? korenron 0 2,304 Dec-31-2020, 01:43 PM
Last Post: korenron
  nmap sagpal 2 2,447 Jun-04-2020, 05:20 PM
Last Post: sagpal
  FIN scan with scapy peterkl 0 5,343 Feb-13-2017, 09:10 PM
Last Post: peterkl

Forum Jump:

User Panel Messages

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