解决Github网页上图片显示失败,gist、raw无法打开的问题

提示
2021.3起,github.com的 IP 开始被间歇性阻断(点此了解更多),本文中的方法可能已过时,建议使用代理进行访问。

解决思路:修改hosts大法

记事本打开C:\Windows\System32\drivers\etc\hosts(此为windows,其他系统也有,路径自查)添加(IP、域名之间是Tab):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# GitHub Start 
# 峡州仙士 20210130 更新
199.232.96.133 user-images.githubusercontent.com
140.82.112.3 github.com
140.82.112.3 gist.github.com
185.199.108.153 assets-cdn.github.com
199.232.96.133 raw.githubusercontent.com
199.232.96.133 gist.githubusercontent.com
199.232.96.133 favicons.githubusercontent.com
199.232.96.133 cloud.githubusercontent.com
199.232.96.133 camo.githubusercontent.com
199.232.96.133 avatars.githubusercontent.com
199.232.96.133 avatars0.githubusercontent.com
199.232.68.133 avatars0.githubusercontent.com
199.232.96.133 avatars1.githubusercontent.com
151.101.184.133 avatars1.githubusercontent.com
151.101.184.133 avatars2.githubusercontent.com
199.232.28.133 avatars2.githubusercontent.com
151.101.184.133 avatars3.githubusercontent.com
199.232.68.133 avatars3.githubusercontent.com
151.101.184.133 avatars4.githubusercontent.com
199.232.68.133 avatars4.githubusercontent.com
151.101.184.133 avatars5.githubusercontent.com
199.232.68.133 avatars5.githubusercontent.com
151.101.184.133 avatars6.githubusercontent.com
199.232.68.133 avatars6.githubusercontent.com
151.101.184.133 avatars7.githubusercontent.com
199.232.68.133 avatars7.githubusercontent.com
151.101.184.133 avatars8.githubusercontent.com
199.232.68.133 avatars8.githubusercontent.com
# GitHub End

运行,命令提示符,输入命令

1
ipconfig/flushdns

,回车

1
2
3
ipconfig /displaydns # 显示dns缓存 
ipconfig /flushdns # 刷新DNS记录
ipconfig /renew # 重请从DHCP服务器获得IP

host来源

主要思路就是使用本地hosts文件对网站进行域名解析,一般的DNS问题都可以通过修改hosts文件来解决,githubCDN域名被污染问题也不例外,同样可以通过修改hosts文件解决,将域名解析直接指向IP地址来绕过DNS的解析,以此解决污染问题。

找到URL

打开github任意未显示图片的网页,使用元素选择器(Ctrl+Shift+C)放在显示不了的图片上,或者在无法显示的图片上右键-检查元素,定位到该图片的标签,那么你得到了它的URL,叫做src属性。

比如

右面网址:
https://avatars2.githubusercontent.com/u/15832957?s=60&v=4

获取IP地址

得到上述网址以后打开IPAddress.com这个网站,在搜索框输入它的域名:

avatars2.githubusercontent.com

回车!!!下面你会看到该域名的信息和IP地址:

可以看出IP是:151.101.184.133,并且是2019.05.05最后更新的,我们就可以使这个IP和域名映射起来。

(其他如果有挂掉的一样使用此方法进行一一映射即可。)

参考资料

https://blog.csdn.net/u013044310/article/details/103882463

https://blog.csdn.net/qq_38232598/article/details/91346392

(您还可以在归档页搜索文章标题)