6 |
7 |
8 |
9 |
11 |
12 | # speed-github
13 |
14 | A tool to solve the problem of slow loading and downloading speed of GitHub in the country.
15 |
16 | ## Reason for slow speed
17 |
18 | CDN, Content Distribute Network, can be literally translated into content distribution network. CDN solves the problem of how to quickly and reliably deliver data from the source site to users.
19 |
20 | When users obtain data, they do not need to obtain it directly from the source site. Through CDN's distribution of data, users can obtain data from a better server, thereby achieving fast access and reducing the load pressure on the source site.
21 |
22 | For some reasons, Github is restricted in China. The main method is`DNS pollution`, which is to inject the wrong IP address of Github into the DNS server, thereby affecting user access.
23 |
24 | ## Solution
25 |
26 | Resolve the GitHub-related domain name into the correct IP address, and then fill it into the local host file. When users visit GitHub, they will no longer resolve the IP address to the DNS server, but use the correct local IP address, which will not be affected by DNS pollution.
27 |
28 | ## Usage
29 | >Tip: run with admin permission, beacase the `/etc/hosts` file need to be modified.
30 |
31 | ``` bash
32 | # Download this repo to local
33 | git clone https://github.com/jvxiao/speed-github.git
34 | cd speed-github
35 |
36 | # install dependencies
37 | pip install -r requirements.txt
38 |
39 | # run
40 | python ./src/dnschecker/main.py
41 |
42 | ```
43 |
44 | ## github-hosts
45 |
46 | After executing the above command, your hosts file will add the following content,and then automatically refresh the local DNS.
47 |
48 | Or you can choose to copy the following content into your hosts file, and manually refresh local DNS with `ipconfig /flushdns`
49 |
50 | ```
51 | # Gennerate by Speed-github
52 |
53 | 185.199.109.154 github.githubassets.com
54 | 140.82.113.21 central.github.com
55 | 185.199.111.133 desktop.githubusercontent.com
56 | 185.199.108.133 camo.githubusercontent.com
57 | 185.199.108.133 github.map.fastly.net
58 | 199.193.116.105 github.global.ssl.fastly.net
59 | 46.82.174.68 gist.github.com
60 | 185.199.109.153 github.io
61 | 20.205.243.166 github.com
62 | 20.205.243.168 api.github.com
63 | 0.0.0.0 raw.githubusercontent.com
64 | 185.199.108.133 user-images.githubusercontent.com
65 | 185.199.111.133 favicons.githubusercontent.com
66 | 185.199.111.133 avatars5.githubusercontent.com
67 | 185.199.108.133 avatars4.githubusercontent.com
68 | 185.199.109.133 avatars3.githubusercontent.com
69 | 185.199.110.133 avatars2.githubusercontent.com
70 | 185.199.109.133 avatars1.githubusercontent.com
71 | 185.199.111.133 avatars0.githubusercontent.com
72 | 185.199.108.133 avatars.githubusercontent.com
73 | 20.205.243.165 codeload.github.com
74 | 3.5.7.17 github-cloud.s3.amazonaws.com
75 | 52.216.152.36 github-com.s3.amazonaws.com
76 | 3.5.29.146 github-production-release-asset-2e65be.s3.amazonaws.com
77 | 3.5.28.168 github-production-user-asset-6210df.s3.amazonaws.com
78 | 52.217.202.177 github-production-repository-file-5c1aeb.s3.amazonaws.com
79 | 185.199.109.153 githubstatus.com
80 | 140.82.112.18 github.community
81 | 185.199.110.133 media.githubusercontent.com
82 |
83 |
84 | # Last modified 2025-04-17 18:12:27
85 | # Star repo at https://github.com/jvxiao/speed-github
86 | ```
87 |
--------------------------------------------------------------------------------
/README-Cn.md:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
10 |
11 | [中文](./README-Cn.md) [English](./README.md)
12 |
13 | # speed-github
14 |
15 | 一个解决github在国内加载和下载速度慢问题的工具
16 |
17 | ### 速度慢原因
18 |
19 | CDN,Content Distribute Network,可以直译成内容分发网络,CDN解决的是如何将数据快速可靠从源站传递到用户的问题。
20 |
21 | 用户获取数据时,不需要直接从源站获取,通过CDN对于数据的分发,用户可以从一个较优的服务器获取数据,从而达到快速访问,并减少源站负载压力的目的。
22 |
23 | 处于某些原因的考虑,Github在国内被限制的访问。其手段主要是通过DNS污染,就是通过向DNS服务器其中注入github错误的IP地址,从而影响用户访问。
24 |
25 |
26 | ### 如何解决
27 |
28 | 将github相关的域名解析成正确的ip, 然后填入本地的host文件中。当用户访问github时就不会再从DNS服务器解析ip, 而是使用本地的正确ip,也就不受DNS污染影响。
29 |
30 |
31 | ## 使用
32 | > Tip: 用管理员(admin)权限运行下面的命令,因为需要对`/etc/hosts`文件做修改
33 |
34 | ``` bash
35 | # 下载仓库到本地
36 | git clone https://github.com/jvxiao/speed-github.git
37 | cd speed-github
38 |
39 | # 安装依赖
40 | pip install -r requirements.txt
41 |
42 | # 执行脚本
43 | python ./src/main.py
44 |
45 | ```
46 |
47 | 执行上述命令后,您的 hosts 文件将添加以下内容,并自动刷新本地 DNS。
48 |
49 | 您也可以选择将以下内容复制到 hosts 文件中,然后使用“ipconfig /flushdns”手动刷新本地 DNS。
50 |
51 | **一个更快的方式** 是直接运行下面的命令,它会自动更新`hosts`文件并且刷新本地DNS
52 |
53 | ```
54 | python src/main.py -w
55 | # 或者
56 | python src/main.py --writehosts
57 | ```
58 |
59 | ## github-hosts
60 |
61 | ```
62 | # Gennerate by Speed-github
63 | 185.199.110.154 github.githubassets.com
64 | 140.82.113.21 central.github.com
65 | 185.199.108.133 desktop.githubusercontent.com
66 | 185.199.108.133 camo.githubusercontent.com
67 | 185.199.108.133 github.map.fastly.net
68 | 146.75.29.194 github.global.ssl.fastly.net
69 | 140.82.112.4 gist.github.com
70 | 185.199.109.153 github.io
71 | 140.82.112.4 github.com
72 | 140.82.114.6 api.github.com
73 | 185.199.111.133 raw.githubusercontent.com
74 | 185.199.109.133 user-images.githubusercontent.com
75 | 185.199.111.133 favicons.githubusercontent.com
76 | 185.199.108.133 avatars5.githubusercontent.com
77 | 185.199.108.133 avatars4.githubusercontent.com
78 | 185.199.110.133 avatars3.githubusercontent.com
79 | 185.199.108.133 avatars2.githubusercontent.com
80 | 185.199.108.133 avatars1.githubusercontent.com
81 | 185.199.108.133 avatars0.githubusercontent.com
82 | 185.199.111.133 avatars.githubusercontent.com
83 | 140.82.112.9 codeload.github.com
84 | 52.216.184.195 github-cloud.s3.amazonaws.com
85 | 3.5.30.165 github-com.s3.amazonaws.com
86 | 16.15.217.215 github-production-release-asset-2e65be.s3.amazonaws.com
87 | 54.231.226.25 github-production-user-asset-6210df.s3.amazonaws.com
88 | 3.5.13.29 github-production-repository-file-5c1aeb.s3.amazonaws.com
89 | 185.199.108.153 githubstatus.com
90 | 140.82.112.17 github.community
91 | 185.199.108.133 media.githubusercontent.com
92 |
93 |
94 | # Last modified 2025-05-16 18:21:39
95 | # Star repo at https://github.com/jvxiao/speed-github
96 | ```
97 |
98 |
99 |
100 | ### 关于
101 |
102 | 该项目从第一次发布之后到这一次更新,隔了有好几年的时间,未来该项目将会持续更新。后续在使用过程中,如果有什么问题,欢迎提issue,我也会及时跟进。
103 |
104 | ## 赞赏
105 |
106 | 如果你喜欢该项目,或者该项目有帮助到你,考虑请作者喝一杯咖啡吧 :coffee:
107 |
108 |
109 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
13 |
14 | [中文](./README-Cn.md) [English](./README.md)
15 |
16 | # speed-github
17 |
18 | A tool to solve the problem of slow loading and downloading speed of GitHub in the country.
19 |
20 | ## Reason for slow speed
21 |
22 | CDN, Content Distribute Network, can be literally translated into content distribution network. CDN solves the problem of how to quickly and reliably deliver data from the source site to users.
23 |
24 | When users obtain data, they do not need to obtain it directly from the source site. Through CDN's distribution of data, users can obtain data from a better server, thereby achieving fast access and reducing the load pressure on the source site.
25 |
26 | For some reasons, Github is restricted in China. The main method is`DNS pollution`, which is to inject the wrong IP address of Github into the DNS server, thereby affecting user access.
27 |
28 | ## Solution
29 |
30 | Resolve the GitHub-related domain name into the correct IP address, and then fill it into the local host file. When users visit GitHub, they will no longer resolve the IP address to the DNS server, but use the correct local IP address, which will not be affected by DNS pollution.
31 |
32 | ## Usage
33 | >Tip: run with admin permission, because the `/etc/hosts` file need to be modified.
34 |
35 | ``` bash
36 | # Download this repo to local
37 | git clone https://github.com/jvxiao/speed-github.git
38 | cd speed-github
39 |
40 | # install dependencies
41 | pip install -r requirements.txt
42 |
43 | # run
44 | python ./src/main.py
45 | ```
46 |
47 | After doing this, copy the content `src/hosts` to update you hosts in `etc`, or you can just relace it. And then run the following command to update local DNS.
48 | ```
49 | ipconfig /flushdns
50 | ```
51 |
52 | **A more quick way**, run the folloing command, which will automaticlly do the all thing for you.
53 |
54 | ```
55 | python src/main.py -w
56 | # or
57 | python src/main.py --writehosts
58 | ```
59 | ## github-hosts
60 |
61 | After executing the above command, your hosts file will add the following content,and then automatically refresh the local DNS.
62 |
63 | Or you can choose to copy the following content into your hosts file, and manually refresh local DNS with `ipconfig /flushdns`
64 |
65 | ```
66 | # Gennerate by Speed-github
67 | 185.199.110.154 github.githubassets.com
68 | 140.82.114.22 central.github.com
69 | 185.199.110.133 desktop.githubusercontent.com
70 | 185.199.109.133 camo.githubusercontent.com
71 | 185.199.108.133 github.map.fastly.net
72 | 146.75.77.194 github.global.ssl.fastly.net
73 | 140.82.112.3 gist.github.com
74 | 185.199.110.153 github.io
75 | 140.82.112.3 github.com
76 | 140.82.114.5 api.github.com
77 | 185.199.109.133 raw.githubusercontent.com
78 | 185.199.109.133 user-images.githubusercontent.com
79 | 185.199.108.133 favicons.githubusercontent.com
80 | 185.199.108.133 avatars5.githubusercontent.com
81 | 185.199.108.133 avatars4.githubusercontent.com
82 | 185.199.108.133 avatars3.githubusercontent.com
83 | 185.199.109.133 avatars2.githubusercontent.com
84 | 185.199.108.133 avatars1.githubusercontent.com
85 | 185.199.108.133 avatars0.githubusercontent.com
86 | 185.199.110.133 avatars.githubusercontent.com
87 | 140.82.112.10 codeload.github.com
88 | 3.5.29.25 github-cloud.s3.amazonaws.com
89 | 3.5.28.65 github-com.s3.amazonaws.com
90 | 52.216.141.4 github-production-release-asset-2e65be.s3.amazonaws.com
91 | 54.231.168.145 github-production-user-asset-6210df.s3.amazonaws.com
92 | 3.5.29.44 github-production-repository-file-5c1aeb.s3.amazonaws.com
93 | 185.199.109.153 githubstatus.com
94 | 140.82.113.18 github.community
95 | 185.199.111.133 media.githubusercontent.com
96 |
97 |
98 | # Last modified 2025-06-03 06:19:24
99 | # Star repo at https://github.com/jvxiao/speed-github
100 | ```
101 |
102 | ## Sponsor me
103 |
104 | If you like this project, or if it helps you, please consider buying the author a cup of coffee :coffee:
105 |
106 |
107 |
--------------------------------------------------------------------------------
/img/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jvxiao/speed-github/a5dceb59b551c980e01c4592b7243f6d081204ba/img/logo.jpg
--------------------------------------------------------------------------------
/img/screenShot.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jvxiao/speed-github/a5dceb59b551c980e01c4592b7243f6d081204ba/img/screenShot.PNG
--------------------------------------------------------------------------------
/img/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jvxiao/speed-github/a5dceb59b551c980e01c4592b7243f6d081204ba/img/success.png
--------------------------------------------------------------------------------
/img/support.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jvxiao/speed-github/a5dceb59b551c980e01c4592b7243f6d081204ba/img/support.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | shutils
2 | dnspython
--------------------------------------------------------------------------------
/src/dnschecker/__init__.pyt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jvxiao/speed-github/a5dceb59b551c980e01c4592b7243f6d081204ba/src/dnschecker/__init__.pyt
--------------------------------------------------------------------------------
/src/dnschecker/hosts.urls:
--------------------------------------------------------------------------------
1 | github.githubassets.com
2 | central.github.com
3 | desktop.githubusercontent.com
4 | central.github.com
5 | camo.githubusercontent.com
6 | github.map.fastly.net
7 | github.global.ssl.fastly.net
8 | gist.github.com
9 | github.io
10 | github.com
11 | api.github.com
12 | raw.githubusercontent.com
13 | user-images.githubusercontent.com
14 | favicons.githubusercontent.com
15 | avatars5.githubusercontent.com
16 | avatars4.githubusercontent.com
17 | avatars3.githubusercontent.com
18 | avatars2.githubusercontent.com
19 | avatars1.githubusercontent.com
20 | avatars0.githubusercontent.com
21 | avatars.githubusercontent.com
22 | codeload.github.com
23 | github-cloud.s3.amazonaws.com
24 | github-com.s3.amazonaws.com
25 | github-production-release-asset-2e65be.s3.amazonaws.com
26 | github-production-user-asset-6210df.s3.amazonaws.com
27 | github-production-repository-file-5c1aeb.s3.amazonaws.com
28 | githubstatus.com
29 | github.community
30 | media.githubusercontent.com
--------------------------------------------------------------------------------
/src/dnschecker/main.py:
--------------------------------------------------------------------------------
1 | from dns import resolver
2 | import time
3 | import os
4 | import shutil
5 |
6 |
7 | # github resource urls
8 | urls_path = os.path.dirname(__file__) + '/hosts.urls'
9 |
10 | def get_github_domains():
11 | with open(urls_path) as fs:
12 | urls = list(map(lambda x:x.replace('\n', ''), fs.readlines()))
13 | return urls
14 |
15 | def get_ip_by_domain(hostname):
16 | try:
17 | ips = resolver.resolve(hostname, 'A')
18 | except:
19 | ips = []
20 | return str(ips[0]) if len(ips) else None
21 |
22 |
23 | def get_all_ips(urls):
24 | host_ip_map = {}
25 | for url in urls:
26 | host_ip_map[url] = get_ip_by_domain(url)
27 | print(url, host_ip_map[url])
28 | return host_ip_map
29 |
30 |
31 | def insert_or_append(file_path, header, tail, insert_content):
32 | startIndex = None
33 | endIndex = None
34 |
35 | if not os.path.exists(file_path):
36 | raise Exception('file not exist')
37 |
38 | with open(file_path, encoding='utf-8') as f:
39 | lines = f.readlines()
40 |
41 | for i, line in enumerate(lines):
42 | if line.strip().find(header.strip()) > -1:
43 | startIndex = i - 1
44 | break
45 |
46 | for i, line in enumerate(lines):
47 | if line.strip().find(tail.strip()) > -1:
48 | endIndex = i + 1
49 | break
50 |
51 | if startIndex is not None and endIndex is not None:
52 | new_content = lines[:startIndex] + insert_content + lines[endIndex:]
53 | else:
54 | new_content = lines + insert_content
55 |
56 | return new_content
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/host-template:
--------------------------------------------------------------------------------
1 | # Gennerate by Speed-github
2 |
3 | {{ hosts }}
4 |
5 | # Last modified {{ time }}
6 | # Star repo at https://github.com/jvxiao/speed-github
--------------------------------------------------------------------------------
/src/hosts:
--------------------------------------------------------------------------------
1 | # Added by Docker Desktop
2 | 192.168.243.1 host.docker.internal
3 | 192.168.243.1 gateway.docker.internal
4 | # To allow the same kube context to work on the host and the container:
5 | 127.0.0.1 kubernetes.docker.internal
6 | # End of section
7 |
8 | 127.0.0.1 jvxiao.test.com
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | # Gennerate by Speed-github
17 |
18 | 185.199.108.154 github.githubassets.com
19 | 140.82.114.21 central.github.com
20 | 185.199.111.133 desktop.githubusercontent.com
21 | 185.199.108.133 camo.githubusercontent.com
22 | 185.199.111.133 github.map.fastly.net
23 | 108.160.169.174 github.global.ssl.fastly.net
24 | 37.61.54.158 gist.github.com
25 | 185.199.108.153 github.io
26 | 20.205.243.166 github.com
27 | 20.205.243.168 api.github.com
28 | 185.199.111.133 raw.githubusercontent.com
29 | 185.199.110.133 user-images.githubusercontent.com
30 | 185.199.111.133 favicons.githubusercontent.com
31 | 185.199.110.133 avatars5.githubusercontent.com
32 | 185.199.108.133 avatars4.githubusercontent.com
33 | 185.199.111.133 avatars3.githubusercontent.com
34 | 185.199.109.133 avatars2.githubusercontent.com
35 | 185.199.109.133 avatars1.githubusercontent.com
36 | 185.199.109.133 avatars0.githubusercontent.com
37 | 185.199.108.133 avatars.githubusercontent.com
38 | 20.205.243.165 codeload.github.com
39 | 16.182.97.49 github-cloud.s3.amazonaws.com
40 | 3.5.17.171 github-com.s3.amazonaws.com
41 | 3.5.29.201 github-production-release-asset-2e65be.s3.amazonaws.com
42 | 52.216.245.172 github-production-user-asset-6210df.s3.amazonaws.com
43 | 16.15.194.110 github-production-repository-file-5c1aeb.s3.amazonaws.com
44 | 185.199.108.153 githubstatus.com
45 | 140.82.114.17 github.community
46 | 185.199.109.133 media.githubusercontent.com
47 |
48 |
49 | # Last modified 2025-04-29 22:01:27
50 | # Star repo at https://github.com/jvxiao/speed-github
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 | import shutil
4 | import getopt
5 | import sys
6 | import platform
7 | from dnschecker.main import get_all_ips, insert_or_append, get_github_domains
8 |
9 |
10 |
11 | cur_dir = os.path.dirname(__file__)
12 |
13 | # host tempalte
14 | template_path = cur_dir + '/host-template'
15 | # temp hosts file
16 | local_host = cur_dir +'/hosts'
17 | if sys.platform == 'win32':
18 | # Windows
19 | host_path = r'C:\Windows\System32\drivers\etc\hosts'
20 | else:
21 | # macOS or Linux
22 | host_path = '/etc/hosts'
23 |
24 | def githubFly(writehost=False):
25 | urls = get_github_domains()
26 | host_map = get_all_ips(urls)
27 |
28 |
29 | host_str = ''
30 | for key in host_map:
31 | if host_map[key] is not None:
32 | host_str += '{0:<30} {1}\n'.format(host_map[key], key)
33 |
34 | with open(template_path) as ft:
35 | template = ''.join(ft.readlines())
36 |
37 | content = '\n\n' + template
38 | content = content.replace('{{ hosts }}', host_str)
39 | content = content.replace('{{ time }}', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) )
40 |
41 | header = '# Gennerate by Speed-github'
42 | tail = '# Star repo'
43 | new_lines = insert_or_append(host_path, header, tail, [content])
44 |
45 | with open(local_host, 'w+', encoding='utf-8') as fh:
46 | fh.writelines(new_lines)
47 |
48 | # overwrite the old hosts
49 | if writehost:
50 | try:
51 | shutil.copy(local_host, host_path)
52 |
53 | # 根据系统类型刷新 DNS 缓存
54 | sys_type = platform.system()
55 | if sys_type == 'Windows':
56 | os.system("ipconfig /flushdns")
57 | elif sys_type == 'Darwin': # macOS
58 | os.system("sudo dscacheutil -flushcache")
59 | os.system("sudo killall -HUP mDNSResponder")
60 | elif sys_type == 'Linux':
61 | os.system("sudo systemd-resolve --flush-caches")
62 | else:
63 | print("[warning] unknown system, DNS not flushed automatically")
64 |
65 | print('\n[success]: let github fly!')
66 | except:
67 | print("\n[write hosts file faild]: permission deny! run as administrator.")
68 |
69 |
70 |
71 | if __name__ == '__main__':
72 |
73 | try:
74 | opts, args = getopt.getopt(sys.argv[1:],"hw", ["writehosts"])
75 | if len(opts) == 0:
76 | githubFly(False)
77 | except:
78 | print("help: python ./src/main.py -h")
79 | sys.exit(2)
80 |
81 | for opt, arg in opts:
82 | if opt == '-h':
83 | print(" [1] automaticly update local hosts file: python src/main.py -w ")
84 | print(" [2] update local hosts file by hand: python src/main.py")
85 | if opt in ('-w', '--writehosts'):
86 | githubFly(True)
87 | else:
88 | githubFly(False)
89 |
90 |
--------------------------------------------------------------------------------
/src/update/readme.template:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
11 |
12 | [中文](./README-Cn.md) [English](./README.md)
13 |
14 | # speed-github
15 |
16 | A tool to solve the problem of slow loading and downloading speed of GitHub in the country.
17 |
18 | ## Reason for slow speed
19 |
20 | CDN, Content Distribute Network, can be literally translated into content distribution network. CDN solves the problem of how to quickly and reliably deliver data from the source site to users.
21 |
22 | When users obtain data, they do not need to obtain it directly from the source site. Through CDN's distribution of data, users can obtain data from a better server, thereby achieving fast access and reducing the load pressure on the source site.
23 |
24 | For some reasons, Github is restricted in China. The main method is`DNS pollution`, which is to inject the wrong IP address of Github into the DNS server, thereby affecting user access.
25 |
26 | ## Solution
27 |
28 | Resolve the GitHub-related domain name into the correct IP address, and then fill it into the local host file. When users visit GitHub, they will no longer resolve the IP address to the DNS server, but use the correct local IP address, which will not be affected by DNS pollution.
29 |
30 | ## Usage
31 | >Tip: run with admin permission, because the `/etc/hosts` file need to be modified.
32 |
33 | ``` bash
34 | # Download this repo to local
35 | git clone https://github.com/jvxiao/speed-github.git
36 | cd speed-github
37 |
38 | # install dependencies
39 | pip install -r requirements.txt
40 |
41 | # run
42 | python ./src/main.py
43 | ```
44 |
45 | After doing this, copy the content `src/hosts` to update you hosts in `etc`, or you can just relace it. And then run the following command to update local DNS.
46 | ```
47 | ipconfig /flushdns
48 | ```
49 |
50 | **A more quick way**, run the folloing command, which will automaticlly do the all thing for you.
51 |
52 | ```
53 | python src/main.py -w
54 | # or
55 | python src/main.py --writehosts
56 | ```
57 | ## github-hosts
58 |
59 | After executing the above command, your hosts file will add the following content,and then automatically refresh the local DNS.
60 |
61 | Or you can choose to copy the following content into your hosts file, and manually refresh local DNS with `ipconfig /flushdns`
62 |
63 | ```
64 | # Gennerate by Speed-github
65 | {{ hosts }}
66 |
67 | # Last modified {{ time }}
68 | # Star repo at https://github.com/jvxiao/speed-github
69 | ```
70 |
71 | ## Sponsor me
72 |
73 | If you like this project, or if it helps you, please consider buying the author a cup of coffee :coffee:
74 |
75 |
76 |
--------------------------------------------------------------------------------
/src/update/updateReadme.py:
--------------------------------------------------------------------------------
1 | import os
2 | import shutil
3 | import sys
4 | from datetime import datetime
5 | from zoneinfo import ZoneInfo
6 |
7 | sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
8 | from dnschecker.main import get_github_domains, get_all_ips
9 |
10 | template_path = 'src/update/readme.template'
11 | temp_file = 'src/update/temp'
12 | readme_path = os.path.join(os.path.dirname(__file__), '../../', 'README.md')
13 | print(readme_path)
14 | if __name__ == '__main__':
15 | urls = get_github_domains()
16 | host_map = get_all_ips(urls)
17 |
18 | host_str = ''
19 | for key in host_map:
20 | if host_map[key] is not None:
21 | host_str += '{0:<30} {1}\n'.format(host_map[key], key)
22 |
23 | with open(template_path) as ft:
24 | template = ''.join(ft.readlines())
25 |
26 | content = '\n\n' + template
27 | content = content.replace('{{ hosts }}', host_str)
28 |
29 | # 获取指定时区的当前时间
30 | tz = ZoneInfo("Asia/Shanghai") # 时区名称(如 "America/New_York")
31 | now = datetime.now(tz)
32 | content = content.replace('{{ time }}', now.strftime("%Y-%m-%d %H:%M:%S"))
33 |
34 | with open(temp_file, 'w+') as fp:
35 | fp.write(content)
36 |
37 | shutil.copy(temp_file, readme_path)
38 | os.remove(temp_file)
--------------------------------------------------------------------------------