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配置!')

最新文章

  1. JS/CSS收藏
  2. electrica writeup
  3. c# txt文件的读写
  4. ff
  5. Netbeans 8.0.2 For PHP继续坑
  6. MATLAB 中NORM运用
  7. noip2008普及组4题题解-rLq
  8. lfs遇到的一些问题--编制LFS
  9. 除trigger()方法外的jquery手动触发事件
  10. 自制EIGRP配置实验大全
  11. 推荐一个比crontab更好用的东西:crongo
  12. spring的配置和使用
  13. [亲测哪步都不能省可用]联想ThinkPad E450装系统后开机一直停留在BootMenu上,无法选择硬盘进入
  14. Spring Boot 系列 @ControllerAdvice 拦截异常并统一处理
  15. tomcat下部署应用helloworld
  16. convertToNodeSpace和convertToWorldSpace ---实际应用
  17. VB.NET只允许打开一个实例
  18. libgdx判断矩形重叠碰撞
  19. 关于java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap的错误解决办法
  20. 发布订阅者模式之C#委托实现

热门文章

  1. php ul li 分类
  2. 使用C#解析并运行JavaScript代码
  3. linux 小技巧
  4. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造
  5. 手脱ASProtect v1.23 RC1(有Stolen Code)
  6. Nginx简介及使用Nginx实现负载均衡的原理【通俗易懂,言简意赅】【转】
  7. 洛谷P2860 [USACO06JAN]冗余路径Redundant Paths
  8. 数学:Burnside引理与Pólya定理
  9. Linux 中使用 dd 测试磁盘性能
  10. adb端口被占用解决