Shop OBEX P1 Docs P2 Docs Learn Events
Ping IP and check for response — Parallax Forums

Ping IP and check for response

barksterbarkster Posts: 7
edited 2011-09-19 12:05 in Accessories
Is it possible to ping an ip address and check for response? If so anyone have an example?

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-09-16 20:13
    Sure, just try to open a socket on a remote server. If socket does not open after some period of time then the ping failed, otherwise the ping was successful.
    http://spinneret.servebeer.com:5000/client/sget.htm
  • TorTor Posts: 2,010
    edited 2011-09-18 03:09
    Weellll.. strictly speaking a socket connection isn't a ping, ping is done via ICMP, not TCP/IP.
    -Tor
  • Mike GMike G Posts: 2,702
    edited 2011-09-18 06:45
    Tor how do you ping an IP address with the Spinneret?
  • TorTor Posts: 2,010
    edited 2011-09-19 06:57
    Mike G wrote: »
    Tor how do you ping an IP address with the Spinneret?
    I have no idea, I'm not familiar with the Spinneret. I was only pointing out that ping != socket connection, as the OP was asking about how to ping.. but I have to correct myself, there's a socket but it's not a TCP/IP connect involved. So if the API for the Spinneret doesn't support ICMP then the correct answer is that there's no way to actually ping an IP address from the Spinneret. If it can do ICMP then you can do ping. In C you would have done something like:
    struct icmp *icmp_pkt = (struct icmp *) some_buffer;
    ..
    icmp_pkt->icmp_type = ICMP_ECHO;
    ..
    proto = getprotobyname ("icmp");
    sock = socket (AF_INET, SOCK_RAW, proto->p_proto);
    ..
    sendto (sock, pkt, ..., (struct sockaddr *) &thepingaddr..);

    -Tor
  • barksterbarkster Posts: 7
    edited 2011-09-19 07:04
    I would like to ping but testing socket connection I guess would work. all I'm trying to do is check if device is on or not essentially
  • TorTor Posts: 2,010
    edited 2011-09-19 07:24
    barkster wrote: »
    I would like to ping but testing socket connection I guess would work. all I'm trying to do is check if device is on or not essentially
    For that Mike G's connect method will work fine. The only issue would be with timeouts. I'm looking at the code but after just a quick look I'm not certain if timeouts are a part of the socket layer level or not.. on ordinary desktop systems and servers there's a timeout buried down in the kernel and the timeout can vary between systems. On Linux the connect would hang for 3 seconds if the remote IP address was unavailable while on AIX it would hang for 75 seconds, just to pick two that I could test right now.

    -Tor
  • barksterbarkster Posts: 7
    edited 2011-09-19 07:24
    Would this work? says it supports icmp and should work with spinneret http://code.google.com/p/spinneret-web-server/wiki/WIZnet_W5100_Overview
  • Mike GMike G Posts: 2,702
    edited 2011-09-19 09:06
    The Spinneret can respond to a ping. There is no mention of an out going ping in the W5100 datasheet or I do not see the feature listed.

    The W5100 reports timeouts via socket registers and interrupts. I, as well as others, tend to poll the status register and use custom timers to determine a timeout.

    Please see the W5100 datasheet and browse the existing code base, there's a lot of information. You might also take a peek at the link in post #2. Let me know if you have any questions.
  • barksterbarkster Posts: 7
    edited 2011-09-19 12:05
    thanks Mike I read over your post #2 and yes i may give this a try... Anyone have better suggestions on using the spinneret to check if a device is online or not? I was thinking of building a small windows service that would check in to the spinneret at periodic intervals but I'd like to be able to ping a list of ip addresses instead. Just want to see if this is the best approach, using a socket to check or trying to ping or some other way? Thanks
Sign In or Register to comment.