#get the fastest github ip
fast_ip=`curl -k https://websites.ipaddress.com/github.global.ssl.fastly.net#ipinfo 2>/dev/null| grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" |sed -n '2p'`;
echo $fast_ip;
#Add or replace the $fast_ip in /etc/hosts
if grep "www.github.com" /etc/hosts >/dev/null;then
echo "github dns exists, replace it with the latest one $fast_ip";
sed -i -e "s|[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} *www\.github\.com|$fast_ip www\.github\.com|" /etc/hosts;
else
echo "github dns does not exist, replace it with the latest one $fast_ip";
echo -e "\n#Github\n$fast_ip www.github.com\n" >> /etc/hosts;
fi
killall -HUP mDNSResponder;say DNS cache has been flushed;
Mac刷新github地址 增加速度
最新推荐文章于 2024-05-20 16:19:24 发布