Wednesday, November 19, 2014

Shell Script To Read IP Address ( Find Ip Address Script )

  1. #!/bin/sh
  2. # Shell script scripts to read ip address
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # -------------------------------------------------------------------------
  10. # Get OS name
  11. OS=`uname`
  12. IO="" # store IP
  13. case $OS in
  14. Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
  15. FreeBSD|OpenBSD) IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
  16. SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
  17. *) IP="Unknown";;
  18. esac
  19. echo "$IP"

0 comments: