Mac上解決訪問github慢之懶人版

寫了一個簡單腳本用來解決Mac上訪問github慢的問題,基本思路如下:

  1. 訪問 http://github.global.ssl.fastly.net.ipaddress.com/#ipinfo 獲取github的IP地址
  2. 在/etc/hosts中加入查詢到的IP和域名 (需要root 權(quán)限)
  3. 在終端在輸以下指令刷新DNS(需要root 權(quán)限)

運(yùn)行以下shell腳本即可,需要root權(quán)限。

#get the fastest github ip
fast_ip=`curl http://github.global.ssl.fastly.net.ipaddress.com/#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;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容