Jump to content
  • 0

lua script to ping ip address and store result in variable


Question

Hi,

I was wondering if anybody had tried this before.

I am looking to ping a device on my home network to see if it is 'online' and then store something like an online/offline in a variable that I can display.

I use static IP's for all the devices I am looking to monitor

 

I was thinking about using the arp approach and see if the device is returned as part of the list

 

Has anybody tried this before .. or do people think it may be possible or is there another route ?

 

Thoughts appreciated

 

Thanks

Frank

Edited by autofrank
Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I don't think there is a 'ping' command available. However, you can try a http or tcp connect. Even if the device at the other end does not have a http or tcp sever. Just let it time out. To try that connection, the system has to 'arp' the IP address. If the device's tcp/ip stack is up and running, it'll answer the arp request and appear in the HC2 arp table. The only downside I immediately see is the fact that arp entries are cached (probably for 10 minutes) so it isn't very precise... If the device has any open TCP connection, you can try to use TCP in a virtual device:

local Tcptest = Net.FTcpSocket(SingleIP, 1400) -- 1400 is port number of upnp port on a SONOS device. Or try 80, 22, even 443...
Tcptest:setReadTimeout(2000)
bytes, errorCode = Tcptest:write("anything")
if errorCode == 0 then -- TCP connection is alive
Not tested, but I've used this kind of code for other stuff.
Link to post
Share on other sites
  • 0

I don't think there is a 'ping' command available. However, you can try a http or tcp connect. Even if the device at the other end does not have a http or tcp sever. Just let it time out. To try that connection, the system has to 'arp' the IP address. If the device's tcp/ip stack is up and running, it'll answer the arp request and appear in the HC2 arp table. The only downside I immediately see is the fact that arp entries are cached (probably for 10 minutes) so it isn't very precise... If the device has any open TCP connection, you can try to use TCP in a virtual device:

local Tcptest = Net.FTcpSocket(SingleIP, 1400) -- 1400 is port number of upnp port on a SONOS device. Or try 80, 22, even 443...
Tcptest:setReadTimeout(2000)
bytes, errorCode = Tcptest:write("anything")
if errorCode == 0 then -- TCP connection is alive
Not tested, but I've used this kind of code for other stuff.

 

 

Hi Peter,

 

That's interesting approach and sounds like it would work.

Perhaps I can get over the arp cache by executing the scene every minute and storing a result (or table of results) in a global variable 

 

I'll give it a shot and report back in case somebody else finds use in what I find out.

 

Thanks for taking the time to reply

 

-Frank

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...