1

I'm working on a utility using Python to discover hardware connected to a network using UDP broadcasts. The devices respond to the UDP boradcast and from there I periodically query their onboard webserver for a data file. After doing some research I've realized it looks like it isn't possible to broadcast and receive responses from the devices on a different subnet. I don't have access to the routers to change configuration and can't guarantee that the broadcast will make it through.

I've looked at this SO question/answer mentioning ip-multicasting but I'm not sure it applies to me because as far as I know the devices aren't capable of joining a multicast group (at least that's my understanding of how ip-multicasting works).

My proposed solution is to use a library like gevent to poll a user-defined range of IP addresses or all IPs on a subnet for the device's data file. This would obviously take a bit of time but wouldn't have to be run often, maybe once a week or month.

So, from my sparse description, is what I've proposed probably the only way to do it? Or could there be a better approach?

Community
  • 1
  • 1
circuitBurn
  • 893
  • 11
  • 24

2 Answers2

1

It seems to me that this is more of a networking issue rather than a python one.

You can't access them by broadcast because you are not on that net and configuration to do so does not seem to be safe at least.

But you can generate individual messsages for each host in a subnet. If the subnet is something like 192.168.1.0/24 (/24 is the same as 255.255.255.0) you should send a message to each of the following hosts:

for i in range(1, (2<<(31-**24**)) - 1):
     print "192.168.1." + str(i)

In this way you generate unicast packages for each one possible host in a subnet. A more general rule for generating ip addresses for a subnet can surely be found online.

elpaquete
  • 241
  • 2
  • 9
0

One way would be to maintain a list of hardware on a peer accessible from all other peers. e.g. a peer accessible on the Internet if all other peers have an Internet connection. When a peer connects to the peer accessible from all others it's IP end point will be know and can be registered. Then other peers could ask for a list of registered peers.

markmnl
  • 11,116
  • 8
  • 73
  • 109