Pinging all the ip addresses on the local network

Tags: #<Tag:0x00007fe22649db20>


I got working
for a single
IPAddress remoteIP(192, 168, 5, 232); hardcoded in particle photon.

my particle photon is on the same network as other hosts are, I have 2 questions :

  1. is it possible to detect other hosts on the network ?
  2. even if its possible or not, I want to know how can I create a list of ip address and iterate over and ping each of the server to find the status .

I am a python programmer and this code I have written following examples.
any help will be greatly appreciated.

Here is some python version of what I want to implement in cpp for the 2nd quesiton:

hosts = {
	"host1":  IPAddress(,
	"host2":  IPAddress(,
	"host3":  IPAddress(,
	"host4":  IPAddress(,

# then I want to iterate over each of the items in the array above

for host, ip_address in hosts.iteritems():
	# do ping on ip_address
	# if ping succeed fine
	# else blink red LED and print status


In C/C++ you’d use an array like this

IPAddress hosts[] = { IPAddress(192, 168, 1, 2), IPAddress(192, 168, 1, 3), ... };
const int hostsCount = sizeof(hosts) / sizeof(hosts[0]);
  for (int i=0; i < hostsCount; hostsCount++) {
    // do something with host[i]

Instead of an array you could use a vector with its iterator syntax but dynamic memory management on embedded systems has its own caveats to consider and I’d also consider this overkill for a static list of possible IPs.


Hello @ScruffR

thanks for a quick reply

apart from that, is it possible to do lookup for hosts from within particle photon.
I can do look if available hosts and store it in eprom instead of always searching for hosts.
and then ping and report in some way for host status.


Depends on the “hosts”
If the make themselves known to the system (e.g. via mDNS) or respond to pings you may be able to, but I’d suspect a fair number of network connected devices may do any of that.


oh no you miss-understood, I didn’t mean that my particle photon should be discoverable.
by lookup I meant, I want particle photon to look for connected devices on the local network.

I read that mdns allows register a device by a name soomething like photon.local or find ip address using the known host name .


Nope, I didn’t misunderstand. I meant exactly that.
Any network client - Particle or not - can decide to make itself known to the rest of the network or not, respond to pings or not, …
Also mDNS is not a Particle invention it’s a common protocol - e.g. Apple Bonjour uses it


oh ok, I am considering storing ip addresses in eprom of particle photon instead of having to discover it.