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