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


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

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

運行以下shell腳本即可,需要root權限。

#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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM