Skip to content

Instantly share code, notes, and snippets.

@ManiaciaChao
Created March 17, 2020 07:53
Show Gist options
  • Save ManiaciaChao/a7498b86867e5c839cc3e2eb53025e77 to your computer and use it in GitHub Desktop.
Save ManiaciaChao/a7498b86867e5c839cc3e2eb53025e77 to your computer and use it in GitHub Desktop.
Get windows host ip in WSL2
# 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 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
# if your default shell is fish, then add this to your config.fish
setenv winhost (grep -G '^nameserver' /etc/resolv.conf | awk '{print $2}')
#! /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"
#! /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
#! /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