How to get IP address in Python all …today i learnt how to get IP address in python..

To get the Hostname

import socket
print socket.gethostname()

To get the IP Address

import socket
print socket.gethostbyname(socket.gethostname())

we can also check with dummy socket and see the host name

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('', 0))

Thats it…:)