5

I'm Writing a script in python2.7 on a windows XP machine. The machine is connected to multiple networks using different network cards.

I'm running into an issue where I've bound a UDP Socket to a specific interface(I understand that you can accomplish this in windows by just providing the network cards existing IP address)

self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind(('10.31.9.0', 6466)) #<<< 10.31.9.0 is address of desired card

I then set the timeout to 5s

self.sock.settimeout(5)

Then I try to send a message out to a server that I can prove exists and works. then wait for a response.

self.destintation = ('10.42.40.34', 62434)

# Send the msg
self.sock.sendto(msg, self.destintation)

# receive data
reply, addr = self.sock.recvfrom(1024)

However a socket.timeout is always thrown. so I open up wire shark to see what is going wrong, and it turns out that my initial message never gets sent on the desired interface.

What I do see is an arp broadcast on a different interface(10.10.10.12 ) from my machine asking who is attached to my desired destination IP:

1   0.000000    IntelCor_8c:6d:97   Broadcast   ARP 42      Who has 10.42.40.34?  Tell 10.10.10.12

Of course there is no response to the broadcast because the 10.42.40.34 Address/machine is not reachable from the 10.10.10.12 interface

How do I tell Python to send the ARP broadcast out on '10.31.9.0'? What have I done Wrong?

EDIT:

Additional Information> The network for the interface I am using is a Class B (netmask is 255.255.0.0)

The interface IP is : 10.31.9.0 

The target IP is: 10.42.40.34. 

I am wondering if the issue is a result of my target sitting on a separate subnet. However, as described in a related issue here. there is traffic from the server to me... =/

UPDATE:

Results of "route PRINT 10*"

Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
         10.0.0.0        255.0.0.0      10.10.10.12     10.10.10.12   10
      10.10.10.12  255.255.255.255        127.0.0.1       127.0.0.1   10
        10.31.0.0      255.255.0.0        10.31.9.0       10.31.9.0   10
        10.31.9.0  255.255.255.255        127.0.0.1       127.0.0.1   10
   10.255.255.255  255.255.255.255      10.10.10.12     10.10.10.12   10
   10.255.255.255  255.255.255.255        10.31.9.0       10.31.9.0   10
Default Gateway:        153.4.84.1
===========================================================================
Persistent Routes:
  None

UPDATE #2 Full route PRINT

Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0       153.4.84.1     153.4.85.81   10
        10.10.0.0      255.255.0.0      10.10.10.12     10.10.10.12   10
      10.10.10.12  255.255.255.255        127.0.0.1       127.0.0.1   10
        10.31.0.0      255.255.0.0        10.31.9.0       10.31.9.0   10
        10.31.9.0  255.255.255.255        127.0.0.1       127.0.0.1   10
   10.255.255.255  255.255.255.255      10.10.10.12     10.10.10.12   10
   10.255.255.255  255.255.255.255        10.31.9.0       10.31.9.0   10
        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1   1
       153.4.84.0    255.255.252.0      153.4.85.81     153.4.85.81   10
      153.4.85.81  255.255.255.255        127.0.0.1       127.0.0.1   10
    153.4.255.255  255.255.255.255      153.4.85.81     153.4.85.81   10
     192.168.56.0    255.255.255.0     192.168.56.1    192.168.56.1   20
     192.168.56.1  255.255.255.255        127.0.0.1       127.0.0.1   20
   192.168.56.255  255.255.255.255     192.168.56.1    192.168.56.1   20
        224.0.0.0        240.0.0.0      10.10.10.12     10.10.10.12   10
        224.0.0.0        240.0.0.0        10.31.9.0       10.31.9.0   10
        224.0.0.0        240.0.0.0      153.4.85.81     153.4.85.81   10
        224.0.0.0        240.0.0.0     192.168.56.1    192.168.56.1   20
  255.255.255.255  255.255.255.255      10.10.10.12     10.10.10.12   1
  255.255.255.255  255.255.255.255        10.31.9.0       10.31.9.0   1
  255.255.255.255  255.255.255.255      153.4.85.81     153.4.85.81   1
  255.255.255.255  255.255.255.255     192.168.56.1    192.168.56.1   1
  255.255.255.255  255.255.255.255     192.168.56.1               5   1
Default Gateway:        153.4.84.1
===========================================================================
Persistent Routes:
  None
4
  • This definitely sounds like a network configuration issue rather than a python one. Can you get the same results using something like the "netcat" tool? Can you use "route PRINT -4" and see what rules for mapping from IP addresses to interfaces are being used? You may have some interfaces with overlapping netmasks (or something similarly bad) such that their is a choice of rules and hence wrong interface is being used. "route" should help you see if that's the case. Commented Jun 29, 2016 at 22:03
  • I don't know what the "-4" flag does, DOS didn't seam to like it. Instead I used "route PRINT 10*". I've Updated my question with the results Commented Jun 30, 2016 at 11:32
  • Yep, you've got overlapping subnets here. The interface 10.10.10.12 is going to be chosen for sending all traffic to 10.x.x.x destinations. The best way to fix this would be to change the network configuration for the 10.10.10.12 interface to avoid the overlap. If 10.10.x.x and 10.31.x.x are meant to be different subnets, then the netmasks should both be 255.255.0.0. (I'm on win 7, so the command line options for "route" may be a little different for you on XP. On win 7, "-4" restricts the output to IPv4 routes.) Commented Jun 30, 2016 at 12:50
  • That makes sense, I owe you big time. I won't be able to test this until sometime next week (bureaucracy at its finest). but if you want to type up an answer ill mark it as "accepted" as soon as I get confermation Commented Jun 30, 2016 at 14:39

2 Answers 2

1

Given the output from "route", it looks like you're 10.10.10.12 and 10.31.9.0 interfaces have been configured with overlapping subnets. The OS is choosing to use 10.10.10.12 for all 10.x.x.x addresses as it's the first rule that applies.

Having overlapping subnets is normally a network configuration error: it's probably intended that 10.10.x.x and 10.31.x.x are the valid subnets and both should use a netmask of 255.255.0.0, and so the current 255.0.0.0 netmask used by the 10.10.10.12 interface is incorrect.

(It may be possible to 'fudge' a fix, if the intention is to make all 10.x.x.x requests use the 10.10.10.12 interface except for those in 10.31.x.x which should use the 10.31.9.0 address, by changing the 'metric' of the 10.31.0.0 routing rule so that anything for 10.31.x.x addresses matches that rule before the 10.x.x.x rule is checked. You can use the route command to make that change, but it's definitely not recommended! Fixing the overlapping subnets is the proper solution.)

Sign up to request clarification or add additional context in comments.

8 Comments

Gahhh... bad news... It didnt work, however I can Now see ARP request go out on the right interface (10.31.9.0 instead of 10.10.10.12)... I've updated the question with a full "route PRINT"... =/
If it's now using the right interface, there's almost certainly something else networking-related that's preventing reaching the server. That's getting a bit away from the original question. How's about grabbing me on chat (chat.stackoverflow.com) and we can try figuring it out?
It says I don't have enough reputation to "chat" there... =/
Sorry, I'd not noticed the minimum reputation requirement. Try again now!
is there another way?
|
-1

Turns out, the Packets that my "server" was sending where not IP kosher. so they where getting rejected at the network and transport layers. Solution was to not use python socket class, but instead communicate directly to OSI-L2 using winpcap and ctypes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.