I need your brainpower...

This is a discussion on I need your brainpower... within the C++ Programming forums, part of the General Programming Boards category; I want to write a small utility that checks to see if a host is live, then either beeps or ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    18

    Exclamation I need your brainpower...

    I want to write a small utility that checks to see if a host is live, then either beeps or plays a WAV file if the network connection goes down. system("ping xyz"); doesn't cut it, as it has no way to tell if the pings failed or not. I looked in the winsock.h file, hoping I'd find some clues in it to do what I need, but no luck. Anyone got any ideas to get me headed in the right direction?
    Thanks!

    Mark
    Language: C++
    Compiler: Borland C++
    OS: Windows NT

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Re: I need your brainpower...

    Originally posted by Util_Mark
    system("ping xyz"); doesn't cut it, as it has no way to tell if the pings failed or not.
    I thought it returned 0 when successful and nonzero when it failed.

    I must check.

    (Edit)
    Yes it does.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    It works.
    Code:
        int status1 = system("ping strandmark.com > nul");
        if (status1 == 0)
            cout << "First succeeded" << endl;
        int status2 = system("ping nonexistant-123.com > nul");
        if (status2 != 0)
            cout << "Second failed" << endl;
    Will print

    Code:
    First succeeded
    Second failed
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    18
    YOU ARE AWESOME vVv!!!! Thanks!!!!
    Language: C++
    Compiler: Borland C++
    OS: Windows NT

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    18

    Question I need your brainpower...

    OK, it works, BUT if I do a loop to check at different intervals, then unplug the network cable of the PC that I'm testing against, the code still says that the host is alive, when in reality it should have failed since it's network connection doesn't exist anymore.

    Do you think I need to flush the ARP table of the address I'm testing against, or do this have nothing to do with it? Weird...

    -Mark
    Language: C++
    Compiler: Borland C++
    OS: Windows NT

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21