问题描述

打开github网页太慢

问题原因

被墙,导致DNS无法访问,实际上通过配置本地域名到IP的映射可以避免查询DNS服务器,从而加快速度。

为了验证确实是DNS的问题,请前往站长之家DNS查询,可以看见很多DNS服务器都没有。

一般Github的访问有两部分:主站的访问和二级域名的资源加载(比如样式文件等)

一般Github加载缓慢,主要是 assets-cdn.github.com、avatars0.githubusercontent.com 以及 avatars1.githubusercontent.com 三个域名的解析问题。(国内很多地方解析不了)

为了提高速度,可以使用HOSTS加速对Github的域名解析。

解决方法

windows C:\Windows\System32\drivers\etc\hosts

linux /private/etc/hosts

修改hosts主机映射文件:

添加github一系列网址的IP地址、域名映射

原理就是:当我们访问github时,那些域名什么的就不需要去DNS服务器上询问了,直接从本地HOST文件中获得。

但是github域名所对应IP好像是随时间变化的,挨个查询太麻烦,来个脚本

先建立一个域名列表haha.txt,下面列表中的gist.github.com是代码片功能,被墙得死死地。无论如何打不开。

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

然后用python语言使用requests+beautifulsoup制作一个小爬虫

import requests
from bs4 import BeautifulSoup for i in open("haha.txt"):
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")
print(x[5].string.strip(),i.strip())

最终得到所要结果

192.30.253.113 github.com
151.101.100.133 assets-cdn.github.com
151.101.100.133 avatars0.githubusercontent.com
151.101.100.133 avatars1.githubusercontent.com
151.101.100.133 documentcloud.github.com
8.7.198.45 gist.github.com
151.101.100.133 help.github.com
192.30.253.121 nodeload.github.com
151.101.100.133 raw.github.com
174.129.214.132 status.github.com
151.101.100.133 training.github.com
23.235.33.133 github.io

关闭浏览器,重新打开,就能体验到飞一般的感觉 !

为了简单,可以通过Python直接更改HOSTS文件,不用手动更改。

s = """
github.com
assets-cdn.github.com
avatars0.githubusercontent.com
avatars1.githubusercontent.com
documentcloud.github.com
help.github.com
nodeload.github.com
raw.github.com
status.github.com
training.github.com
github.io
"""
import requests
from bs4 import BeautifulSoup ans = []
for i in s.split():
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")
x = "%s %s" % (x[5].string.strip(), i.strip())
print(x)
ans.append(x) hosts = r"C:\Windows\System32\drivers\etc\hosts"
with open(hosts, "r") as f:
content = [i for i in f.readlines() if i.startswith("#")]
content.extend(ans)
with open(hosts, "w") as f:
f.write("\n".join(content))

github访问太慢解决方案的更多相关文章

  1. github访问很慢解决方案

    首先要解决的就是这个访问速度的问题: 获取Github相关网站的ip 访问https://www.ipaddress.com,拉下来,找到页面中下方的“IP Address Tools – Quick ...

  2. 解决www.github.com访问太慢的问题

    解决www.github.com访问太慢的问题 使用www.github.com的过程中,有时候打开会特别的慢,原因github.com的域名被一堵伟大的墙挡在了外面.但是我们可以通过修改本机的hos ...

  3. 【亲测有效】Github无法访问或者访问速度的解决方案

    我相信,很多朋友都遇到了 Github 访问速度过慢的问题,我也是在此记下笔记,方便以后拿来使用. 第一步.修改Hosts 通过问题的搜索了解到 github 访问很慢一般通过修改 hosts 文件解 ...

  4. github 入门教程之 github 访问速度太慢怎么办

    github 是全世界最流行的开源项目托管平台,其代表的开源文化从根本上改变了软件开发的方式. 基本上所有的需求都能从 github 上或多或少找到现成的实现方案,再也不用重头开始造轮子而是自定义轮子 ...

  5. 加速Github访问

    Github 仓库的数据传输很慢,甚至可能导致仓库拉取失败.例如: remote: Enumerating objects: , done. remote: Counting objects: % ( ...

  6. 远程客户端连接MysqL数据库太慢解决方案

    远程客户端连接MysqL数据库太慢解决方案局域网客户端访问mysql 连接慢问题解决. cd /etc/mysql vi my.conf [mysqld] skip-name-resolve 此选项禁 ...

  7. 转: 解决Github访问超慢问题

    转自:http://zengrong.net/post/2092.htm 解决Github访问超慢问题 Github is so slowly. 这段时间访问 github 都非常慢,google了一 ...

  8. 转: Github访问慢解决办法

    from: https://yq.aliyun.com/articles/36744 Github访问慢解决办法   zxiaofan 2016-04-20 17:25:00 浏览2156 评论0 摘 ...

  9. 解决Github访问超慢问题[自己留档]

    解决Github访问超慢问题 Github is so slowly. 这段时间访问 github 都非常慢,google了一下发现是github某个CDN被伟大的墙屏蔽所致. 出问题的应该是这个CD ...

随机推荐

  1. 《mahout实战》

    <mahout实战> 基本信息 原书名:Mahout in action 作者: (美)Sean Owen    Robin Anil    Ted Dunning    Ellen Fr ...

  2. JAVA常见算法题(三十三)---求子串在字符串中出现的次数

    计算某字符串中子串出现的次数. public static void main(String[] args) { String s1 = "adcdcjncdfbcdcdcd"; ...

  3. kafka-manager:kafak的管理界面的安装和使用

    下载打包 release下载:https://github.com/yahoo/kafka-manager/releases 源码位置:https://github.com/yahoo/kafka-m ...

  4. python2 和 python3兼容写法

    一:使用ImportError,Python3中将一些Python2的模块名称做了修改,需要我们做一些处理来保证代码在不同Python版本中能够正常运行 # -*- coding: utf- -*- ...

  5. python中的归并排序

    本来在博客上看到用python写的归并排序的程序,然后自己跟着他写了一下,结果发现是错的,不得不自己操作.而自己对python不是非常了解所以就变百度边写,最终在花了半个小时之后就写好了. def m ...

  6. 【Cocos2d-X开发学习笔记】第12期:动作类CCAction的详细讲解

    一般对于游戏中的精灵而言,它们不仅仅是存在于场景中,而且是动态展现的,例如,精灵移动的动态效果.动 画效果.跳动效果.闪烁和旋转动态效果等.每一种效果都可以看成是精灵的一个动作. 一.动作类(CCAc ...

  7. EF操作增删改查

    lianxiEntities db = new lianxiEntities();//上下文的入口 #region //EF Added //UserInfo user = new UserInfo( ...

  8. idea 创建 简单的scala maven项目

    1.创建maven scala项目 2.maven配置 <properties> <scala.version>2.11.8</scala.version> < ...

  9. Oracle根据字段值找到表名和列名

    方法1: --Oracle 根据字段值查询其所在的表.字段 DECLARE CURSOR cur_query IS SELECT table_name, column_name, data_type ...

  10. 自定义cas客户端核心过滤器AuthenticationFilter

    关于cas客户端的基本配置这里就不多说了,不清楚的可以参考上一篇博文:配置简单cas客户端.这里是关于cas客户端实现动态配置认证需要开发说明. 往往业务系统中有些模块或功能是可以不需要登录就可以访问 ...