1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Check for LAN/WAN connection?

Discussion in 'Mac Programming' started by Locker, Sep 17, 2010.

  1. macrumors 6502

    #1
    Hello,

    I want an app to check whether it has a connection to a local server (via host-name or IP)... and also check whether it has a connection to the Internet (this can be by checking google.com if needs be).

    If anyone could point me towards the easiest way to do this it would be much appreciated :)
     
  2. macrumors 6502

    87vert

    #2
    you should be able to do a simple applescript to check for that.
     
  3. macrumors 6502

    #3
    Okay, so say I have something like:

    Code:
    if (do shell script "ping host-name") contains "1 packets received" then...
    How exactly would I integrate this into a cocoa app? So that the fact it was running that ping was unknown to the user. And... how would it pass the results of the ping back to the cocoa app?

    Sorry, I'm new to this :eek:
     
  4. macrumors regular

  5. macrumors 6502

    #5
    I did do a search in Google. Unfortunately most examples use SCNetworkReachability methods which will return true even if the host isn't responding. Anyone know any alternatives to that? I imagined this would be pretty easy to do...
     
  6. macrumors regular

    #6
  7. macrumors 6502

    #7
  8. macrumors 68020

    Krevnik

    #8
    Yeah, you pretty much have to approach this with two layers. SCNetworkReachability is your first layer which tells you if it is even worth trying to hit the network. The second layer is to check the host itself, and the links provided is exactly what you need.

    This works well for providing a status mechanism on a server without having to actually open a connection to it.

    If you intend to open a connection anyways, you might as well make the connection once SCNetworkReachability says you've got a connection that will work. It's almost always wasted effort to ping a server immediately before opening the connection, as they have similar timeouts for Ping vs TCP connections.
     

Share This Page