From 51acb0f283ed29e03b14af58ce2bad6a7fb977e8 Mon Sep 17 00:00:00 2001 From: KMohZaid <68484509+KMohZaid@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:47:25 +0530 Subject: [PATCH] update(fix host ip): using gateway ip, nameserver ip not working --- assets/GWSL_helper.sh | 16 ++++++++-------- manager.py | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/assets/GWSL_helper.sh b/assets/GWSL_helper.sh index e463a463..98629a85 100644 --- a/assets/GWSL_helper.sh +++ b/assets/GWSL_helper.sh @@ -41,19 +41,19 @@ then then # Configure Fish sed -i.bak '/DISPLAY /d' ~/.config/fish/config.fish - echo "set -gx DISPLAY (cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}'):0.0 #GWSL" >> ~/.config/fish/config.fish + echo "set -gx DISPLAY (ip route list default | awk '{print \$3; exit;}'):0.0 #GWSL" >> ~/.config/fish/config.fish elif [ $wsl_shell == "zsh" ] then # Configure Zsh sed -i.bak '/DISPLAY=/d' ~/.zshrc - echo "export DISPLAY=\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}'):0.0 #GWSL" >> ~/.zshrc + echo "export DISPLAY=\$(ip route list default | awk '{print \$3; exit;}'):0.0 #GWSL" >> ~/.zshrc elif [ $wsl_shell == "bash" ] then # Configure Bash sed -i.bak '/DISPLAY=/d' ~/.profile - echo "export DISPLAY=\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}'):0.0 #GWSL" >> ~/.profile + echo "export DISPLAY=\$(ip route list default | awk '{print \$3; exit;}'):0.0 #GWSL" >> ~/.profile sed -i.bak '/DISPLAY=/d' ~/.bashrc - echo "export DISPLAY=\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}'):0.0 #GWSL" >> ~/.bashrc + echo "export DISPLAY=\$(ip route list default | awk '{print \$3; exit;}'):0.0 #GWSL" >> ~/.bashrc fi fi @@ -91,19 +91,19 @@ then then # Configure Fish sed -i.bak '/PULSE_SERVER /d' ~/.config/fish/config.fish - echo "set -gx PULSE_SERVER tcp:(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}') #GWSL" >> ~/.config/fish/config.fish + echo "set -gx PULSE_SERVER tcp:(ip route list default | awk '{print \$3; exit;}') #GWSL" >> ~/.config/fish/config.fish elif [ $wsl_shell == "zsh" ] then # Configure Zsh sed -i.bak '/PULSE_SERVER=/d' ~/.zshrc - echo "export PULSE_SERVER=tcp:\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}') #GWSL" >> ~/.zshrc + echo "export PULSE_SERVER=tcp:\$(ip route list default | awk '{print \$3; exit;}') #GWSL" >> ~/.zshrc elif [ $wsl_shell == "bash" ] then # Configure Bash sed -i.bak '/PULSE_SERVER=/d' ~/.profile - echo "export PULSE_SERVER=tcp:\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}') #GWSL" >> ~/.profile + echo "export PULSE_SERVER=tcp:\$(ip route list default | awk '{print \$3; exit;}') #GWSL" >> ~/.profile sed -i.bak '/PULSE_SERVER=/d' ~/.bashrc - echo "export PULSE_SERVER=tcp:\$(cat /etc/resolv.conf | grep nameserver | awk '{print \$2; exit;}') #GWSL" >> ~/.bashrc + echo "export PULSE_SERVER=tcp:\$(ip route list default | awk '{print \$3; exit;}') #GWSL" >> ~/.bashrc fi fi diff --git a/manager.py b/manager.py index e10e5675..5ff6b954 100644 --- a/manager.py +++ b/manager.py @@ -779,7 +779,7 @@ def get_ip(machine): :return: """ #print("get_ip") - cmd = "wsl.exe -d " + str(machine) + ' ' + "/bin/sh -c " + '"' + """(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""" + '"' + cmd = "wsl.exe -d " + str(machine) + ' ' + "/bin/sh -c " + '"' + """(ip route list default | awk '{print $3}')""" + '"' #print(cmd) @@ -795,15 +795,15 @@ def get_ip(machine): try: ipa = ipaddress.ip_address(result) except: - cmd = "wsl.exe -d " + str(machine) + ' ' + "/bin/sh -c " + '"' + """echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""" + '"' - result = os.popen(cmd).readlines()[0] + cmd = "wsl.exe -d " + str(machine) + ' ' + "/bin/sh -c " + '"' + """echo $(ip route list default | awk '{print $3; exit;}')""" + '"' + result = os.popen(cmd).readlines()[0].rstrip("\n") #result = "localhost" #print("ipa", ipa, "ipd") - #result = runo3(machine, """echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')""") + #result = runo3(machine, """echo $(ip route list default | awk '{print $3; exit;}')""") #print("ip", result, "done") return result # [0][:-1]