http://blog.csdn.net/sunsteam/article/details/63253933
http://tool.chinaz.com/dns
151.101.196.249 github.global.ssl.fastly.net
151.101.196.133 assets-cdn.github.com
vi /etc/hosts
C:\Windows\System32\drivers\etc
yum install -y nscd
/etc/rc.d/init.d/nscd restart
我们在命令行中输入/etc/rc.d/init.d/nscd restart,更新DNS缓存。此时,重新访问github,奇迹诞生了,访问速度嗖嗖的,完美解决访问慢的问题。妈妈再也不用 担心猿的继续深造了,大家可以试试,为人民服务。
一、修改DNS,加快GitHub访问
echo "151.101.196.249 github.global.ssl.fastly.net" >> /etc/hosts
echo "151.101.196.133 assets-cdn.github.com" >> /etc/hosts
/etc/rc.d/init.d/nscd restart
上面只是一个示例,为了能真正找到所在地区的最快DNS,建议使用下面的Python3脚本进行动态获取
# # pip3 install beautifulsoup4
# pip3 install requests
import requests
from bs4 import BeautifulSoup
import os
import json list = [
'github.com',
'assets-cdn.github.com',
'avatars0.githubusercontent.com',
'avatars1.githubusercontent.com',
'documentcloud.github.com',
'gist.github.com',
'help.github.com',
'nodeload.github.com',
'raw.github.com',
'status.github.com',
'training.github.com',
'github.io'] host='/etc/hosts'
cmd='/etc/rc.d/init.d/nscd restart'
hostlines=[] GitHubDomainList=[] #将文件读取到内存中
with open(host,"r",encoding="utf-8") as f:
hostlines = f.readlines() for i in list:
url = "http://ip.chinaz.com/" + i.strip()
resp = requests.get(url)
soup = BeautifulSoup(resp.text)
x = soup.find(class_="IcpMain02")
x = x.find_all("span", class_="Whwtdhalf")
j_str='{\"ip\":\"'+x[5].string.strip()+'\",\"domain\":\"'+i.strip()+'\"}'
mes=json.loads(j_str)
GitHubDomainList.append(mes) # 删除掉GitHub的域名IP定义
with open(host,encoding="utf-8",mode="w") as f_w:
for line in hostlines:
found=False
for c in GitHubDomainList:
if c["domain"] in line:
found=True
break
if not found:
f_w.write(line+'\n') # 追加到最后GitHub的域名IP定义
with open(host,encoding="utf-8",mode='a') as f_w:
for a in GitHubDomainList:
f_w.write(a['ip'] + " " + a["domain"]+'\n')
# 执行DNS刷新命令
print(os.popen(cmd).read())
print('恭喜,成功完成GitHub的最优DNS配置!')