Forum Archive

Sockets

ihf

I was writing something that needs the iPad's ipaddress.

ip = socket.gethostbyname(socket.gethostname())

results in

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

Is there a way to find the ipaddress?

ccc

OMZ's code was:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8',80))
print s.getsockname()[0]
s.close()

As documented in the thread http://omz-forums.appspot.com/pythonista/post/5778981575983104