Edit:
Added new information below.
I am using the attached ping.py to send ICMP echo requests to a /24 subnet I am part of.
I am doing this so that a ARP resolution request will be sent for each host and those which are alive will show up as valid entries in the ARP table. I extract these to process them further.
I am using a customized version of https://github.com/feross/SpoofMAC. I patched it to make it work on pyhton 3.4 and widnows7 and winxp. Also added some code for easy debugging.
In this example, I skipped the spoofmac code and hardcoded its role. It just asks to choose a Ethernet adapter and returns the gateway IP which is given to the build function.
Sample:
import ping
def build_arp(ip):
for i in range(1, 255):
dest = ip.split('.')
dest[3] = str(i)
des = '.'.join(dest)
print(ping.echo(des,.001))
build_arp('192.168.1.1')
Running this code in a /24 I am not part of takes less than a second. Ouput of all the requets is None which means tiemout.
But if I run this in a subnet I am currently connected to, each request after the first one(to the gateway which responds <1ms) have a 3 seconds delay. By delay, I mean the request is not sent.The code waits for some thing. I can't figure out why the delay is there. The same code works fine in WinXP virtual machine on the same physical machine. Takes about 3 second to do it's job of finding the alive hosts.
Here is the ping.py
Edit:----------------------------------------
Here is the original source:
https://gist.github.com/warvariuc/9246335#file-ping-py
Running this unmodified file on the xp virtual machine, the timeouts are instant.
But on the win7 host, the timeouts seem to take 3-5 seconds. Also, the local host is not responding in the win7 host.
Edit2:---------------------------------------
The _ss.close() system call in socket.py(line 244, python3.4.1) is taking about 3 seconds to finish. The same call in XP is done in less than a nanosecond. Now I have the culprit.