Advertisement
starbeamrainbowlabs

networkinfo

Apr 8th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #from http://unix.stackexchange.com/questions/74699/get-network-information-through-ubuntu-terminal
  4.  
  5. if ! /bin/ip route | grep -q ^default; then
  6.   echo "No Internet connection"
  7.   echo
  8.   exit 0
  9. fi
  10. if="$(/bin/ip route |
  11.  awk '$1 == "default" {for (i=2;i<=NF;i++) if ($i == "dev") { i++;print $i; exit}}')"
  12. if [ -z "$if" -o \! -e /sys/class/net/"$if" ]; then
  13.   echo "Sorry, some error, aborting."
  14.   echo
  15.   exit 1
  16. fi
  17. if /usr/sbin/iw dev "$if" info &>/dev/null; then
  18.   echo "The Internet connection is wireless."
  19.   echo
  20.   # uncomment the next line to start iwconfig
  21.   # iwconfig
  22. else
  23.   echo "The Internet connection is wired."
  24.   echo
  25. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement