Originally Posted by vegaseat
It might depend on what OS you are using, but here is one way ...
[php]# socket.getaddrinfo returns a list of tuples
# tuple[4][0] of each list element is the IP address
import socket
addrs = socket.getaddrinfo(socket.gethostname(), None)
for addr in addrs:
print addr[4][0]
[/php]
I just tested your code, that just gets the internal ip, would he need his external IP?
In a perfect world exceptions would not be needed.