Hacker News new | ask | show | jobs
by artificialLimbs 1679 days ago

    #!/bin/zsh
    ip addr | grep $localNetworkPrefix
    ping $localGateway
    ping 1.1.1.1
    ping $DNS01
    ping $DNS02
    open -a Safari https://downdetector.com/status/%1
Do `chmod +x ./scriptname.sh` to make executable and run with argument (e.g. net.sh facebook) to check a particular service.

Edit: Thanks @Shared404

2 comments

ip doesn't exist on macOS. That is a Linuxism.

You can use the following:

   netstat -rn -f inet | grep default | head -n 1 | awk '{ print $2 }'
To get the default gateway that is the preferred one on macOS, so you don't need to hard code it.

  scutil --dns
Will display the DNS servers/split DNS configuration as well.
I still type 'ip a s' on osx machines multiple times a week, even though I know it doesn't exist for many years.

If on wifi one can also simply option click the wifi icon in the menu bar. Maybe some people don't know yet, it was a late discovery for me option click shows more information there.

For quick internet access check I like 'curl ipconfig.sh'

I'm on my phone but I think you can do this if you're using awk anyway:

  netstat -rn -f inet | awk '/default/ {print $2;exit}'
> Edit: Not sure how to do single spaced newline here.

If you prepend each line with 4 spaces it'll format as code.

  I believe only 2 spaces
  are required.