2

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

http://pastebin.com/neuMVg4p

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.

pteek
  • 43
  • 4
  • It's not fully clear to me - did you try running the same code on the very same computer with different OS (xp/7)? Alternatively, are you positive there's no other difference than xp vs 7 in the two test setups? – Grzegorz Oledzki Jul 20 '14 at 20:37
  • I have a xp Virtual machine running on the win7 system as guest inside VMware. The Ethernet adapter is bridged to the virtual machine. – pteek Jul 23 '14 at 14:34
  • I have a workaround for now. I will simply apply all the processing done to each mac one after one. So, rather than building the long list of alive hosts, I will process each host as they are found. Still, it's an interesting bug. It will still be slower than the XP version. – pteek Jul 23 '14 at 14:50
  • 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. – pteek Jul 23 '14 at 15:11
  • Okay. So this only happens on win7 when the ARP is not resolved. There is a call to socket.close(). This call is where the code waits for 3 seconds if ARP is not resolved under win7. BUT, removing the call does not affect the wait. The code still waits before the control leaves the block(?). – pteek Jul 23 '14 at 16:13
  • 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. – pteek Jul 23 '14 at 18:21
  • It seems like this has something to do with blocking and non-blocking sockets. – pteek Jul 25 '14 at 14:15

0 Answers0