Answers for "how to get your pc ip address instead of 127.0.0.1 python socket programming"

1

python get lan ip

import socket
def get_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except Exception:
        IP = '127.0.0.1'
    finally:
        s.close()
    return IP
Posted by: Guest on June-19-2020

Code answers related to "how to get your pc ip address instead of 127.0.0.1 python socket programming"

Python Answers by Framework

Browse Popular Code Answers by Language