2021-09-10更新

注意:以下教程仅适用于windows,因为我没有ios的电脑
注意:该解决方法会覆盖原有的 hosts 文件,食用前建议提前备份一下 hosts 文件

旧版教程只能解决一时的燃眉之急,然而主机的ip地址是实时刷新的,为了实时获取github的ip,所以我们可以用爬虫脚本查询域名对应的ip,再写入hosts文件内,本来这里想用多线程的,发现如果同时多次访问的话会报403(访问拒绝)错误,刚学的多进程也没用上,为了稳定点,就不加了

传送门:exe文件

新版教程

以下的爬虫脚本是参考了@店长github faster这篇文章改写的
因个人水平能力有限,如有更好的建议麻烦在评论区指出
需要用到的模块:requests,bs4,time

源码

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
total_github_ip='''github.com
github.githubassets.com
central.github.com
desktop.githubusercontent.com
assets-cdn.github.com
camo.githubusercontent.com
github.map.fastly.net
github.global.ssl.fastly.net
gist.github.com
github.io
github.com
api.github.com
raw.githubusercontent.com
user-images.githubusercontent.com
favicons.githubusercontent.com
avatars5.githubusercontent.com
avatars4.githubusercontent.com
avatars3.githubusercontent.com
avatars2.githubusercontent.com
avatars1.githubusercontent.com
avatars0.githubusercontent.com
avatars.githubusercontent.com
codeload.github.com
github-cloud.s3.amazonaws.com
github-com.s3.amazonaws.com
github-production-release-asset-2e65be.s3.amazonaws.com
github-production-user-asset-6210df.s3.amazonaws.com
github-production-repository-file-5c1aeb.s3.amazonaws.com
githubstatus.com
github.community
media.githubusercontent.com'''
import os,requests,bs4,multiprocessing,threading,time
hosts = r'C:\Windows\System32\drivers\etc\hosts' #修改路径
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'} #伪造头部,防止403
url = 'https://ip.tool.chinaz.com/' #域名-ip转换网站
list_total_ip = list(total_github_ip.split()) #将上面所有github的域名转换为列表
dns = [] #成功者的储存列表
listproxy = [] #ip获取失败的失败者列表
print('*' * 50)
print('\tWarning\n请以管理员身份运行,否则可能不成功')
print('*' * 50)

def write_files(dns):
f = open(hosts,'w')
for i in range(len(dns)):
f.write(dns[i]+'\n')
print('done!')
f.close()

def main(i): #主函数
try:
r = requests.get(url+list_total_ip[i],headers=headers,timeout=5)
soup=bs4.BeautifulSoup(r.text,'html.parser')
data = soup.find(class_="pop-table-tbody")
data= data.find('span',id='IpValue')
last = "%s %s" % (list_total_ip[i],data.string)
print(last)
dns.append(last)
except:
listproxy.append(i) #将失败者统统关进监狱
for j in range(len(list_total_ip)): #执行主函数
main(j)
if listproxy:
for a in range(len(listproxy)): #再给失败者一次机会,重新请求一次失败者的ip
time.sleep(1) #慢工出细活
main(listproxy[a])
write_files(dns) #等上面的程序都执行完了再写入hosts文件内
os.system('ipconfig /flushdns') #刷新缓存

exe文件

下载链接:蓝奏云 密码:875t

旧版教程

  1. 按次序打开以下文件:此电脑->C盘->Windows->System32->drivers->etc,编辑hosts文件,将以下内容加进hosts文件
    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
    185.199.108.154               github.githubassets.com
    140.82.113.22 central.github.com
    185.199.108.133 desktop.githubusercontent.com
    185.199.108.153 assets-cdn.github.com
    185.199.108.133 camo.githubusercontent.com
    185.199.108.133 github.map.fastly.net
    199.232.69.194 github.global.ssl.fastly.net
    140.82.113.3 gist.github.com
    185.199.108.153 github.io
    140.82.114.4 github.com
    140.82.112.6 api.github.com
    185.199.108.133 raw.githubusercontent.com
    185.199.108.133 user-images.githubusercontent.com
    185.199.108.133 favicons.githubusercontent.com
    185.199.108.133 avatars5.githubusercontent.com
    185.199.108.133 avatars4.githubusercontent.com
    185.199.108.133 avatars3.githubusercontent.com
    185.199.108.133 avatars2.githubusercontent.com
    185.199.108.133 avatars1.githubusercontent.com
    185.199.108.133 avatars0.githubusercontent.com
    185.199.108.133 avatars.githubusercontent.com
    140.82.113.9 codeload.github.com
    52.217.88.28 github-cloud.s3.amazonaws.com
    52.216.238.99 github-com.s3.amazonaws.com
    52.216.26.252 github-production-release-asset-2e65be.s3.amazonaws.com
    52.217.101.68 github-production-user-asset-6210df.s3.amazonaws.com
    52.217.48.84 github-production-repository-file-5c1aeb.s3.amazonaws.com
    185.199.108.153 githubstatus.com
    64.71.168.201 github.community
    185.199.108.133 media.githubusercontent.com
  2. 完成,然后你就会发现你访问GitHub的速度将会大幅度提升