Created
December 10, 2020 07:34
-
-
Save iamoverit/18d4e9598868614210c262fe5753f165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
Get windows_ip:wsl_ip | |
''' | |
import socket | |
import re | |
import subprocess | |
reg = re.compile('\(WSL\).*?IPv4 Address.*?:.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', flags=re.DOTALL|re.UNICODE) | |
win_ip = reg.findall(subprocess.check_output(['ipconfig.exe']).decode('utf-8'))[0] | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect((win_ip, 1)) | |
lin_ip = s.getsockname()[0] | |
result = "{0}:{1}".format(win_ip, lin_ip) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment