Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. # View IP Address
  2. myip() {
  3. if [ -z "$1" ] || [ "$1" == "--help" ]; then
  4. echo "Usage: myip OPTION
  5.  
  6. OPTIONS:
  7. --remote displays remote (internet) IP Address
  8. --local displays local IP Address(s)
  9. --help display this help and exit
  10.  
  11. NOTE: Dependency 'dig' from dnsutils package to fetch remote address";
  12. elif [ "$1" == "--remote" ]; then
  13. dig +short myip.opendns.com @resolver1.opendns.com
  14. elif [ "$1" == "--local" ]; then
  15. case "$(uname -s)" in
  16.  
  17. Darwin|Linux)
  18. ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
  19. ;;
  20.  
  21. CYGWIN*|MINGW32*|MSYS*)
  22. ipconfig | awk '$1 == "IPv4" {print $NF}'
  23. ;;
  24.  
  25. esac
  26. else
  27. echo "Invalid arguments supplied. Use --help for more information"
  28. fi
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement