This is a small python script which can be used to extract the local IP address of a host in function of his interface. You can modify this script to adapt it to your purposes. ;)

GiddyUp_and_Bickham_Script_by_vladstudio.jpg

#!/usr/bin/python
# Shell script scripts to read ip address
# -------------------------------------------------------------------------
# Copyright (c) 2008 Greg theClimber <http://www.theclimber.be/>
# This script is licensed under GNU GPL version 3.0
# -------------------------------------------------------------------------
from commands import *
import getopt
import sys

def usage():
	print "Usage : python getip.py [(-i | --interface) name]"

try:
	opts, args = getopt.getopt(sys.argv[1:], "hi:", ["help", "interface="])
except getopt.GetoptError, err:
	# print help information and exit:
	print str(err) # will print something like "option -a not recognized"
	usage()
	sys.exit(2)
intf = None
for o, a in opts:
	if o in ("-h", "--help"):
		usage()
		sys.exit()
	elif o in ("-i", "--interface"):
		intf = a
	else:
		assert False, "unhandled option"

os=getoutput('uname')
ifs=getoutput('ifconfig | grep "Ethernet" | grep -v "vnet" | cut --delimiter=L -f1').splitlines()
interfaces=[]

linux="ifconfig %s | grep 'inet '| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'"
freebsd="ifconfig %s | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'"
sunos="ifconfig -a %s | grep inet | grep -v '127.0.0.1' | awk '{ print $2}'"

if not intf:
	print "Please select the interface to use :"
	for n, i in enumerate(ifs):
		i = i.rstrip(' ')
		interfaces.append(i)
		print "%s) %s" % (n, i)
	print "default = 0"
	try:
		num = input()
		num = int(num)
		i = interfaces[num]
	except: num=0
else:
	i = intf

if i:
	if os == 'Linux':
		ip = getoutput(linux % i)
	elif os =='FreeBSD':
		ip = getoutput(freebsd % i)
	elif os == 'SunOS':
		ip = getoutput(sunos % i)
	else:
		ip = "Unknown"
#	print "%r:%r" % (i, ip)

print ip