Wishing I could PING
Just sayin...
I wish we had a PING (ICMP) that is...
I can jury rig one by telneting into myself and sending the command there. But, that's just a janky way of doing it.
I wish we had a PING (ICMP) that is...
I can jury rig one by telneting into myself and sending the command there. But, that's just a janky way of doing it.
Comments
http://www.amxforums.com/showthread.php?6488-Ping_URL_n_GET_IP
Thanks Vinning. But, I already can do this in spades.
I'm wanting to do a good ole fashioned ICMP message (Ping)
I want to ping an IP device from the Netlinx master in code.
We cannot do this in Netlinx. (as far as I know) attempting to do so results in nothing we can process in our sandbox.
Jeff
SEND_STRING dvMaster, "'192.168.1.21',13" DATA_EVENT[dvMaster] { STRING:{ SEND_STRING 0, DATA.TEXT } }On my office master NI-3100 (I believe) which is loaded with a bunch of unorganized code from years of testing crap so I don't know what is really running in the background or what define program code/FB there might be I still get pretty decent results using the telnet through code method.
If I use Diagnostics "Control Device" to send to my virtual device "'PING_IP:192.168.1.33" which is my router and then 'PING_IP:yahoo.com'" to test a ping on the WAN side. From the virtual receiving the command it then opens a socket with the master's telnet port and gives it the ping command with the desired IP or name.
Both tests took only 2 seconds from receiving the commnand to closing the socket and getting my offline event, again on a system running alot of crappy code.
To Router (192.168.1.33)
To Yahoo.com through the router above which is behind another router that acts as the gateway:
Here's an example of the string with the additional command to notify a device so that the ping result will be sent to a specified device's string event handler so you can use the results in the code that needs it.
Based on my meagre readings on the subject, Java doesn't provide access to the ICMP protocol. According to its documentation Java 5.0's InetAddress.isRecahable() function seems to use the underlying OS's ICMP implementation but we do not have access to Java 5.0 in Duet.
Most people who need to implement this functionality in Java seem to be using another active port on the target devices (such as the echo service on port 7) to perform pseudo-pings instead of relying on the ICMP ping mechanism.
The following returns a java.lang.SecurityException: Not supported by platform
Process ping = Runtime.getRuntime().exec("ping " + host);Which pretty much only leaves us with using JNI to run native code to access raw socket functionality (which I think requires that vxWorks on the control system is up to a certain version, which I don't believe it is).
Telnetting into the master and pinging a device from the console seems to be the easiest and onlyiest way to go for the time being
briefly
CHAR ip_master[] = {'192.168.1.198'} INTEGER port_master = 23 test_string = "'ping 192.168.1.21'" IP_CLIENT_OPEN(dvMaster.PORT, ip_master, port_master, IP_TCP) ; SEND_STRING dvMaster, "test_string,13" DATA_EVENT[dvMaster] { STRING:{ SEND_STRING 0, DATA.TEXT } }I feel like I must be causing some kind of infinite loop of send_strings, but I don't get exactly how. I do see the command going twice actually:
PROGRAM_NAME='main' DEFINE_DEVICE dvMaster = 0:5:0 vdvMaster = DYNAMIC_VIRTUAL_DEVICE dvTP = 5555:1:0 DEFINE_VARIABLE VOLATILE INTEGER cCommStatus CHAR test_string[64] CHAR ip_master[] = {'192.168.1.198'} INTEGER port_master = 23 CHAR ip_test[] = {'192.168.1.21'} DEFINE_CALL 'Master Connect' { ip_client_close(dvMaster.PORT) IP_CLIENT_OPEN(dvMaster.PORT, ip_master, port_master, IP_TCP) ; } DEFINE_START CALL 'Master Connect' test_string = "'ping ',ip_test" DEFINE_EVENT DATA_EVENT[dvMaster] { STRING:{ SEND_STRING 0, DATA.TEXT } ONLINE:{ cCommStatus = TRUE } OFFLINE:{ cCommStatus = FALSE } ONERROR:{ cCommStatus = TYPE_CAST(DATA.NUMBER) } } BUTTON_EVENT[dvTP, 1] { PUSH:{ SEND_STRING dvMaster, "test_string,13" } } BUTTON_EVENT[dvTP, 2] { PUSH:{ CALL 'Master Connect' } } DEFINE_PROGRAMVining,
Does having this connection open to 127.0.0.1 preclude anyone else opening one on the AN IP? In other words, do you lock some out by being on the internal IP?
E
nah, don't do that. I'm not crippled. I can hobble over and do it myself. I was just hoping you knew it in your brain. Thanks!
e
I honestly didn't expect you to do that but truthfully I knew you would. You're too inquisitive to resist.
Thank you kind sir!
E