1''' 2Get windows_ip:wsl_ip 3''' 4 5import socket 6import re 7 8with open("/etc/resolv.conf") as f: 9 match = re.search("^nameserver +(?P<win_ip>[0-9.]+)$", f.read(), re.MULTILINE) 10 if match: 11 win_ip = match.group("win_ip") 12 else: 13 raise Exception("Can't find windows ip in resolv.conf") 14 15s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 16s.connect((win_ip, 1)) 17lin_ip = s.getsockname()[0] 18 19result = "{0}:{1}".format(win_ip, lin_ip) 20print(result) 21