In my early coding days. I created a script that will grab certen IP's like external IP, the machine's IP, the active interfaces and the IP associated with the active interface. I made this code for training. I just found this code on my HDD recently and I find it interesting wich command's I used to grab the IP's. I dont know maybe you find this interesting and usefull in a way.
Code
"""IP_grabber by The_R (2011)"""
import socket
import os
print "\033[1;32m[+] \033[1;m External IP: "
cmd = "wget -q -O - http://myexternalip.com/raw"
print
os.system(cmd)
print
Interface_ip = socket.gethostbyname(socket.gethostname())
print "\033[1;32m[+] \033[1;m Machine's IP: "
print
print Interface_ip
print
print "\033[1;34m[!]\033[1;m Active interfaces:"
active_interfaces = "ifconfig -a | grep 'Link encap' | awk '{ print $1 '}"
os.system(active_interfaces)
print
cmd1 = "ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
cmd2 = "ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"
interface = raw_input("\033[1;31m[?]\033[1;m What is your interface? ")
if interface == 'wlan0':
print
print "\033[1;32m[+] \033[1;m IP associated with your interface: %s" % (interface)
print
os.system(cmd1)
elif interface == 'eth0':
print
print "\033[1;32m[+] \033[1;m IP associated with your interface: %s" % (interface)
print
os.system(cmd2)
else:
print
print "\033[1;31mNo IP found\033[1;m"Regards,

