Skip to content

Instantly share code, notes, and snippets.

@iamoverit
Created December 10, 2020 07:34
Show Gist options
  • Save iamoverit/18d4e9598868614210c262fe5753f165 to your computer and use it in GitHub Desktop.
Save iamoverit/18d4e9598868614210c262fe5753f165 to your computer and use it in GitHub Desktop.
#!/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