Continually ping when no connection? (terminal.app)

Discussion in 'macOS' started by johannnn, Sep 6, 2011.

  1. johannnn macrumors 6502a

    johannnn

    Joined:
    Nov 20, 2009
    Location:
    Sweden
    #1
    Hi everyone!

    When there is internet and I ping like "ping google.com", it keeps pinging. If internet goes down, it changes to "Request timeout for icmp_seq 559" but keeps pinging.
    However, if there is no internet connection when I start pinging, it just says "ping: cannot resolve google.com: Unknown host" and stops.

    When I start pinging when Internet is down, how do I make it keep pinging so I know when my Internet is back up?

    Thanks!
     
  2. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #2
    The basic problem in your direct question is that your computer does not know the address of "www.google.com", so it has to ask the DNS system. But since you have no connection, that request goes nowhere... and fast.

    If you were to have an IP address that you can use (I use the DNS servers of a major University that I have long since memorized), then you could use that.

    But the best way would be to use the SystemConfiguration framework to detect when your network comes up. This can be done through the scutil command-line tool. You will need to read the man page and play with it a bit, since it has been a while since I have played with it.
     
  3. speacock, Sep 7, 2011
    Last edited: Sep 7, 2011

    speacock macrumors member

    Joined:
    Jul 26, 2011
    Location:
    UK
    #3
    As larkost said, use an IP address not a hostname, probably the easiest IP address to use would be one for your ISP's DNS servers: easily found, doesn't affect anyone except your ISP, unlikely to change, and the root cause of the problem you first identified.

    Having said that, pinging things constantly is not generally a good idea:
    1. Many servers are set to not respond to ICMP requests anyway
    2. Constant ICMP requests are sometimes a sign of a DoS attack and therefore are not a very friendly thing to do

    If you do it, then make sure to set the interval to something less aggresive than the 1s default, use something like -i 60

    You could try using something like Little Snitch. I don't use it, but understand it has a connection monitor.

    On another note, how unreliable is your internet connection if you need to do this?
     
  4. johannnn thread starter macrumors 6502a

    johannnn

    Joined:
    Nov 20, 2009
    Location:
    Sweden
    #4
    Thanks for all answers. This week the Internet is crappy due to construction work so this comes in handy.

    As you both recommended, I will use a DNS adress. Googles DNS server 8.8.8.8 is the easiest thing in the world to remember, so it's perfect.
     

Share This Page