问题描述

打开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. 一直困扰设计师多年的Android 单位 dp

    轻松理解Android开发单位DP ,让设计与开发高度匹配,整合了网上各大资料汇总一个通俗易懂的. 一直困扰设计师多年的Android 单位 dp 设计这么多年了,相信很多设计师,一直被DP搞得晕头转 ...

  2. IIS HTTPS 禁用不安全的SSL2.0

    禁用: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\Schannel\Protocols 验证:

  3. cout的输出格式初探

    在C++中,cout代表的是标准输出设备,即显示器,相对于C语言中所使用的printf函数,cout显得更为灵活.下面以30.300和1024三个数为例子,简单说明cout输出时所选格式的输出.cou ...

  4. 开启hadoop和Hbase集群的lzo压缩功能(转)

    原文链接:开启hadoop和Hbase集群的lzo压缩功能 问题导读: 1.如何启动hadoop.hbase集群的压缩功能? 2.lzo的作用是什么? 3.hadoop配置文件需要做哪些修改? 首先我 ...

  5. Java数据库编程技术

    1. 建立数据库连接 例1.1 使用JDBC-ODBC桥来连接一个Access数据库. 该数据库的名称为FirstExample,在ODBC数据源中的名称为forStudy,用户名和密码均为空. pa ...

  6. design-twitter

    https://leetcode.com/problems/design-twitter/ class Twitter { unordered_map<int, set<int> & ...

  7. 关于DLL文件和EXE文件不在同一目录下的设置【转】

    https://www.cnblogs.com/chaosimple/archive/2012/08/13/2636181.html 关于DLL文件和EXE文件不在同一目录下的设置 在开发程序结束后, ...

  8. Valid Parentheses leetcode java

    题目: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

  9. Spark性能优化:数据倾斜调优

    前言 继<Spark性能优化:开发调优篇>和<Spark性能优化:资源调优篇>讲解了每个Spark开发人员都必须熟知的开发调优与资源调优之后,本文作为<Spark性能优化 ...

  10. 【记录】cygwin下折腾个人配置环境

    (本文由hcbbt发布,转载请注明出处,blog.csdn[dot]net/hcbbT)      cygwin是windows下的linux的模拟环境,不仅可以执行linux的各种命令,可以在cyg ...