Created
March 17, 2020 07:53
-
-
Save ManiaciaChao/a7498b86867e5c839cc3e2eb53025e77 to your computer and use it in GitHub Desktop.
Get windows host ip in WSL2
This file contains 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
# if your default shell is bash, then add this to your .bashrc | |
export winhost=`grep -G '^nameserver' /etc/resolv.conf | awk '{print $2}'` |
This file contains 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
# this file is an example for how to set a http proxy for git protocol | |
Host github.com | |
HostName github.com | |
User git | |
ProxyCommand ncat --proxy $winhost:7890 %h %p |
This file contains 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
# if your default shell is fish, then add this to your config.fish | |
setenv winhost (grep -G '^nameserver' /etc/resolv.conf | awk '{print $2}') |
This file contains 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
#! /bin/sh | |
# proxychains wrapper | |
PROXY_PORT=7891 # replace with your socks5 port | |
PROXY_IP=$winhost | |
conf=/tmp/proxychains.conf.$$ | |
cat << EOF > $conf | |
strict_chain | |
proxy_dns | |
remote_dns_subnet 224 | |
tcp_read_time_out 15000 | |
tcp_connect_time_out 8000 | |
[ProxyList] | |
EOF | |
echo "socks5 $PROXY_IP $PROXY_PORT" >> $conf | |
trap "rm -f $conf" INT TERM | |
proxychains -q -f "$conf" "$@" | |
ec="$?" | |
rm -f "$conf" |
This file contains 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
#! /bin/bash | |
# this script will add `winhost` to your /etc/hosts | |
rule=$winhost" winhost" | |
if ! grep -G "winhost$" /etc/hosts >/dev/null | |
then | |
echo $rule >> /etc/hosts | |
else | |
echo "/winhost$/c$rule" | |
sed -i "/winhost$/c$rule" /etc/hosts | |
fi | |
This file contains 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
#! /bin/bash | |
# this script returns your winhost | |
grep -G '^nameserver' /etc/resolv.conf | awk '{print $2}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment