📜  python get lan ip - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:41.709000             🧑  作者: Mango

代码示例3
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