python获取本机IP 发表于 2018-07-21 | 分类于 python | 12345678910import socketdef get_host_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip = s.getsockname()[0] finally: s.close() return ip