Monday, May 29, 2006

Python note: get your ip address

Here is a small platform independent script for you to get the IP address for the current machine.

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

1 comment:

Xi.Cheng said...

Excellent tip!~
should be an "aha!" section

import socket

print socket.gethostname()
print socket.gethostbyname(socket.gethostname())
print socket.gethostbyaddr(socket.gethostbyname(socket.gethostname()))

it tells the story easier than starting from scratch about binary, ip-addr-formation or something