• : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.
  • : Function ereg() is deprecated in /home/tcdaemon/tygerclan-Prod/site/includes/file.inc on line 649.

Script to get Network Interface IP

Here is a easy little script to get the IP of a specific interface.  It supports both IPv4 and IPv6. 

#!/bin/bash 


function showSyntax() {
	echo "SYNTAX: $(basename ${0}) (-4|-6) -i INTERFACE"
	echo "  -4,--ipv4 Show IPv4 IP"
	echo "  -6,--ipv6 Show IPv6 IP"
	echo 
        echo "EXAMPLE: $(basename ${0}) -4 -i eth0"
	return 0
}

while [ ! -z ${1} ] ; do
	case ${1} in 
		-4|--ipv4)
			IPV4=true
			
		;;
		-6|--ipv6)
			IPV6=true
			
		;;
		-i|--interface)
			shift
			INTERFACE=${1}
		;;
		*)
			echo "Invalid parameter: ${1}"
			showSyntax
			exit 1
		;;
	esac
	shift
done

if [ -z ${INTERFACE} ] ; then
	showSyntax
	exit 1
fi 


IPV4=${IPV4:-false}
IPV6=${IPV6:-false}

if ${IPV4} ; then 
	/sbin/ifconfig ${INTERFACE} | perl -wne 's/^\s*inet addr:((\d{1,3}\.){3}\d{1,3}).*$/$1/ && print;' 
fi 

if ${IPV6} ; then 
	/sbin/ifconfig ${INTERFACE} |grep 'inet6 addr:'|sed -e 's/\ *//'|cut -d\  -f 3|sed -r 's/\/[[:digit:]]{1,3}//'
fi