探测当前终端使用的IP
使用curl命令发包,去访问外部的站点,查看响应回来的ip,就能知道本终端的ip是什么了。
xxx@xxxMacBook-Pro ~ % curl ip.sb
xxx.xxx.xxx.69
设置代理
根据自己的shell命令解释器来进修改配置,我这里举例zsh。
sudo vim ~/.zshrc
# where proxy
proxy () {
export http_proxy="http://127.0.0.1:1087"
export https_proxy="http://127.0.0.1:1087"
echo "HTTP Proxy on"
}
# where noproxy
noproxy () {
unset http_proxy
unset https_proxy
echo "HTTP Proxy off"
}
最后让配置生效一下:source ~/.zshrc
,然后通过在当前的终端窗口输入proxy
,noproxy
打开或者关闭代理即可。注意,需要在每个终端窗口都打开一次。
打开了代理之后,同样可以使用curl ip.sb 命令查看一下是否正常代理上了。