Is there a command where, when entered outputs information such as:

  • If the network connection is wired or wireless
  • if it is a wireless network, the name of the wireless network
  • How strong the signal is

Just type in terminal 'iw' and then press Tab and you will see something like iw iw iwconfig iwevent iwgetid iwlist iwpriv iwspy all those are related to wireless internet, try iwconfig to show statistic about signal and network interface.


You can make this a shell script for the first question:


if ! /bin/ip route | grep -q ^default; then
  echo "No Internet connection"
  exit 0
if="$(/bin/ip route | 
  awk '$1 == "default" {for (i=2;i<=NF;i++) if ($i == "dev") { i++;print $i; exit}}')"
if [ -z "$if" -o \! -e /sys/class/net/"$if" ]; then
  echo "Sorry, some error, aborting."
  exit 1
if /usr/sbin/iw dev "$if" info &>/dev/null; then
  echo "The Internet connection is wireless."
  # uncomment the next line to start iwconfig
  # iwconfig
  echo "The Internet connection is wired."

You can save this as e.g. ~/scripts/gatewayinfo.sh, make it executable via chmod a+x ~/scripts/gatewayinfo.sh and easily call it by making an alias definition (in e.g. ~/.alias): alias inetinfo="~/scripts/gatewayinfo.sh"

  • The above script as a wgettable pastebin: pastebin.com/raw.php?i=JYB3GRFE – starbeamrainbowlabs Apr 8 '14 at 14:51
  • I'm getting the following error when running the script: line 23: syntax error near unexpected token `fi' I don't know much about shell scripting syntax, but if I remove it the script then says unexpected end of script (which I expected). Do you know how to fix this? – TheRyan722 Jan 28 '16 at 5:28
  • @TheRyan722 No idea. Maybe some copying error? The MD5 hash for the file (with trailing newline) should be: c65bfba31903b4caaadf6adf1da6284b If that is the same for you: What is the output of bash -vx ./testscript.sh? – Hauke Laging Jan 28 '16 at 6:41
  • The exact same thing as the script. Also getting errors about $'\r' not being a valid command. – TheRyan722 Feb 7 '16 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.