Comment 2 for bug 1818615

Revision history for this message
Haw Loeung (hloeung) wrote :

Perhaps something like this, which we use in various other places, to work out the primary / default IP address used by the unit to communicate with the world:

| def get_ip_address():
| # http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
| import socket
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
| # No connection is actually made to this address, so there are no firewalling requirements.
| s.connect(('91.189.89.199', 123))
| ip = s.getsockname()[0]
| s.close()
| return netaddr.IPAddress(ip)