GitHub访问速度提升(解决无法访问)

内容纲要

GitHub访问速度提升

插件

GeasyFork安装Github增强下载

修改Hosts

  1. 找到hosts文件(win/linux下路径不同)

    • windows:C:\Windows\System32\drivers\etc
    • linux:/etc/hosts
    • hosts文件需要授予编辑权限,右键->属性->安全->Users->授予修改权限
  2. 打开DNS检测网站域名检测网站TTL值最小的IP地址

    • 如下表所示,依次查找网址,如要偷懒,也可以只改github.com,添加入hosts文件尾部即可
    # GitHub520 Host Start
    13.229.188.59                  github.com
    185.199.109.154               github.githubassets.com
    151.101.228.133                camo.githubusercontent.com
    151.101.228.133                github.map.fastly.net
    31.13.65.18                github.global.ssl.fastly.net
    31.13.83.34                   gist.github.com
    185.199.108.153               github.io
    192.30.255.116                  api.github.com
    151.101.108.133                raw.githubusercontent.com
    151.101.228.133                user-images.githubusercontent.com
    151.101.108.133                favicons.githubusercontent.com
    151.101.108.133                avatars5.githubusercontent.com
    151.101.108.133                avatars4.githubusercontent.com
    151.101.108.133                avatars3.githubusercontent.com
    151.101.108.133                avatars2.githubusercontent.com
    151.101.108.133                avatars1.githubusercontent.com
    151.101.108.133                avatars0.githubusercontent.com
    13.250.162.133                 codeload.github.com
    52.217.67.220                github-cloud.s3.amazonaws.com
    52.217.67.220                 github-com.s3.amazonaws.com
    52.217.93.220                 github-production-release-asset-2e65be.s3.amazonaws.com
    52.217.12.92                github-production-user-asset-6210df.s3.amazonaws.com
    52.216.244.52                 github-production-repository-file-5c1aeb.s3.amazonaws.com
    # GitHub520 Host End
  3. 自动化方案

# encoding:utf-8
import requests
import re
import random
import time

domain_list=[
    'github.com',
]

github_subdomain=[
    'gist',
    'assets-cdn',
]

githubusercontent_subdomain=[
    'raw',
    'gist',
    'cloud',
    'camo',
    'user-images',
    'avatars',
]

avatars_list=[]
for num in range(9):
    avatars_list.append("avatars"+str(num))

#https://github.com.ipaddress.com/
headers={
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
}

def isIP(str):
    p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
    if p.match(str):
        return True
    else:
        return False

hosts={}
print("处理domain...")
for domain in domain_list:
    url="https://"+domain+".ipaddress.com/"
    response = requests.get(url=url,headers=headers)
    raw_data=response.text
    pattern = re.compile(r'<tr><th>IP Address</th><td><ul class="comma-separated"><li>(.*?)</li></ul></td></tr>')
    find_data=pattern.findall(raw_data)
    if find_data:
        hosts[find_data[0]]=domain
    else:
        hosts['None']=domain
    time.sleep(1)
print("处理github_subdomain...")
for subdomain in github_subdomain:
    url = "https://github.com.ipaddress.com/"+subdomain+".github.com"
    response = requests.get(url=url,headers=headers)
    raw_data = response.text
    pattern = re.compile(r'<tr><th>IP Address</th><td><ul class="comma-separated"><li>(.*?)</li></ul></td></tr>')
    find_data = pattern.findall(raw_data)
    if find_data:
        hosts[find_data[0]]=subdomain+".github.com"
    else:
        # 目前不做处理,进行预设
        PreIP = ['185.199.108.153', '185.199.109.153', '185.199.110.153', '185.199.111.153']
        hosts[PreIP[random.randint(0, 3)]] = subdomain+".github.com"
    time.sleep(1)
print("处理githubusercontent_subdomain...")
global duplicate_data
for subdomain in githubusercontent_subdomain:
    url = "https://githubusercontent.com.ipaddress.com/"+subdomain+".githubusercontent.com"
    response = requests.get(url=url,headers=headers)
    raw_data = response.text
    pattern = re.compile(r'<tr><th>IP Address</th><td><ul class="comma-separated"><li>(.*?)</li></ul></td></tr>')
    find_data = pattern.findall(raw_data)
    if find_data:
        hosts[find_data[0]]=subdomain+".githubusercontent.com"
        duplicate_data=find_data[0]
    else:
        hosts['None']=subdomain+".githubusercontent.com"
    time.sleep(1)
    # 已知githubusercontent_subdomain为重复数据,跳出
    break

ErrorData={}
print("======================Valid-Data======================")
for ip,domain in hosts.items():
    if ip != "None":
        print(ip+"    "+domain)
    else:
        # 查询异常的ip,暂无需处理
        ErrorData[ip]=domain
# 重复数据处理
for duplicateData in githubusercontent_subdomain[1:]:
    print(duplicate_data+"    "+duplicateData + ".githubusercontent.com")
for duplicateData in avatars_list:
    print(duplicate_data+"    "+duplicateData + ".githubusercontent.com")
print("======================================================")

其他

  1. git clone xxx
    • 将github.com换成gitee.com地址
    • 用插件下载,再放入项目文件夹下
    • 修改hosts,速度够快直接从github.com也可以

发表评论