Tuesday, October 11, 2011

shell script to get ip address

#########################################################################
## Name    :    get-ip-address.sh
## Author  :    Saurabh Gupta
## Date    :    PM 08:52 11 October 2011
## Desc    :    get the IP address
## Source  :    http://saurabhgupta0527.blogspot.com/p/shell-scipt.html
## Note    :   
#########################################################################

echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "XXXXXXX   Getting the Network Interface Card Information    XXXXXXX"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

IPLIST=`/sbin/ifconfig | grep "Bcast" | sed -e "s/.*addr:\([^ ]*\).*/\1/"`
 
echo    "These are the current interfaces found on this system:"
cnt=0
for ii in $IPLIST; do
  let cnt=$cnt+1
  iface=`/sbin/ifconfig | awk '$0 ~ str{print b}{b=$1}' str="$ii"`
  echo "[$cnt] $iface ($ii)"
  LISTIP=( "${LISTIP[@]}" $ii )
  LISTIF=( "${LISTIF[@]}" $iface )
done
echo ""
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 


#
# OUTPUT
#
#[sgupta@rhel6x64 scripts]$ . ./get-ip-address.sh
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#XXXXXXX   Getting the Network Interface Card Information    #XXXXXXX
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
#These are the current interfaces found on this system:
#[1] eth0 (192.168.22.64)
#[2] virbr0 (192.168.122.1)
#
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#

2 comments:

  1. it worked correctly.
    thank you.

    ReplyDelete
  2. thnaks. let me know if you need any other scripts.

    --Saurabh Gupta
    saurabh.gupta@ccplusplus.com

    ReplyDelete