diff --git a/get_routable_ip.py b/get_routable_ip.py new file mode 100644 index 0000000..cf392c8 --- /dev/null +++ b/get_routable_ip.py @@ -0,0 +1,18 @@ +"""Some useful functions.""" + +import socket + + +def get_ip(): + """Return the primary, routable, IP address. + From https://stackoverflow.com/a/28950776 + """ + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.connect(('10.255.255.255', 1)) + IP = s.getsockname()[0] + except: + IP = '127.0.0.1' + finally: + s.close() + return IP