├── .github └── workflows │ └── main.yml ├── .gitignore ├── README.md ├── bin └── github_host ├── conf └── config.json ├── github_host ├── __init__.py ├── api.py ├── get_ip_utils.py ├── github.py └── libs │ └── json_conf.py ├── hosts ├── hosts-routeros.txt ├── main.py └── requirements.txt /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: auto CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: "0 2 * * *" 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - name: Set up Python 3.8 20 | uses: actions/setup-python@v5 21 | with: 22 | python-version: 3.8 23 | 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 28 | 29 | - uses: actions/cache@v4 30 | if: startsWith(runner.os, 'Linux') 31 | with: 32 | path: ~/.cache/pip 33 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 34 | restore-keys: | 35 | ${{ runner.os }}-pip- 36 | 37 | - name: Update Deny Host 38 | run: | 39 | pwd 40 | python main.py 41 | 42 | - name: Push to built branch 43 | uses: Automattic/action-commit-to-branch@master 44 | with: 45 | branch: 'master' 46 | commit_message: 'Update Host' 47 | env: 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | /.vscode 3 | /.idea 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-host 2 | 3 | ## 墙介绍 4 | 5 | 被 qiang 大体有两种:DNS污染,封杀IP。 6 | 7 | DNS污染则无法通过域名直接访问,一种方法就是修改DNS,这个最简单的就是修改hosts。 封杀IP的话,只能通过 “反墙” 来解决。由于政策风险,这里不介绍。 8 | 9 | ## github访问 10 | 11 | 由于众所周知的原因 github 很多时候无法加载,或者样式不显示。我们可以简单修改 Host,解决 github 无法访问。编辑下面文件: 12 | **C:\Windows\System32\drivers\etc\hosts**。把上述hosts文件内容复制进去即可。 13 | 14 | 15 | ## 更新 16 | 17 | github 子域名非常多,服务器非常多,墙是动态的。所以需要不断更新 hosts 来解决无法访问问题。 18 | 19 | 20 | -------------------------------------------------------------------------------- /bin/github_host: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import github_host 4 | 5 | if __name__ == '__main__': 6 | github_host.main() 7 | -------------------------------------------------------------------------------- /conf/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "sites": [ 3 | "github.global.ssl.fastly.net", 4 | "assets-cdn.github.com", 5 | "documentcloud.github.com", 6 | "gist.github.com", 7 | "gist.githubusercontent.com", 8 | "github.githubassets.com", 9 | "help.github.com", 10 | "nodeload.github.com", 11 | "raw.github.com", 12 | "status.github.com", 13 | "training.github.com", 14 | "avatars.githubusercontent.com", 15 | "avatars0.githubusercontent.com", 16 | "avatars1.githubusercontent.com", 17 | "avatars2.githubusercontent.com", 18 | "avatars3.githubusercontent.com", 19 | "avatars4.githubusercontent.com", 20 | "avatars5.githubusercontent.com", 21 | "avatars6.githubusercontent.com", 22 | "avatars7.githubusercontent.com", 23 | "avatars8.githubusercontent.com", 24 | "favicons.githubusercontent.com", 25 | "codeload.github.com", 26 | "github-cloud.s3.amazonaws.com", 27 | "github-com.s3.amazonaws.com", 28 | "github-production-release-asset-2e65be.s3.amazonaws.com", 29 | "github-production-user-asset-6210df.s3.amazonaws.com", 30 | "github-production-repository-file-5c1aeb.s3.amazonaws.com", 31 | "githubstatus.com", 32 | "github.community", 33 | "media.githubusercontent.com", 34 | "camo.githubusercontent.com", 35 | "raw.githubusercontent.com", 36 | "cloud.githubusercontent.com", 37 | "user-images.githubusercontent.com", 38 | "customer-stories-feed.github.com", 39 | "pages.github.com", 40 | "api.github.com", 41 | "live.github.com", 42 | "githubapp.com", 43 | "github.dev", 44 | "github.com" 45 | ] 46 | } -------------------------------------------------------------------------------- /github_host/__init__.py: -------------------------------------------------------------------------------- 1 | from github_host.github import Github 2 | 3 | def main(): 4 | github=Github() 5 | github.updateHost() -------------------------------------------------------------------------------- /github_host/api.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianboy/github-host/6765170c026086ce61d4056dca4c227bd94b4d95/github_host/api.py -------------------------------------------------------------------------------- /github_host/get_ip_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | ''' 4 | @Contact : liuyuqi.gov@msn.cn 5 | @Time : 2019/08/03 17:02:15 6 | @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved. 7 | @Desc : get ip from ip address 8 | ''' 9 | 10 | from email import header 11 | import requests 12 | from bs4 import BeautifulSoup 13 | import re 14 | import json 15 | 16 | 17 | def getIpFromIpaddress(site): 18 | headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/737.36(KHTML, like Gecke) Chrome/52.0.2743.82 Safari/537.36', 19 | 'Host': 'ipaddress.com'} 20 | url = "https://ipaddress.com/search/" + site 21 | trueip = None 22 | try: 23 | res = requests.get(url, headers=headers, timeout=5) 24 | soup = BeautifulSoup(res.text, 'html.parser') 25 | ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", res.text) 26 | result = soup.find_all('div', class_="comma-separated") 27 | for c in result: 28 | if len(ip) != 0: 29 | trueip = ip[0] 30 | except Exception as e: 31 | print("查询" + site + " 时出现错误: " + str(e)) 32 | return trueip 33 | 34 | 35 | def getIpFromChinaz(site): 36 | headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/737.36(KHTML, like Gecke) Chrome/52.0.2743.82 Safari/537.36', 37 | 'Host': 'ip.tool.chinaz.com'} 38 | url = "http://ip.tool.chinaz.com/" + site 39 | trueip = None 40 | try: 41 | res = requests.get(url, headers=headers, timeout=5) 42 | soup = BeautifulSoup(res.text, 'html.parser') 43 | result = soup.find_all('span', class_="Whwtdhalf w15-0") 44 | for c in result: 45 | ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", c.text) 46 | if len(ip) != 0: 47 | trueip = ip[0] 48 | except Exception as e: 49 | print("查询" + site + " 时出现错误: " + str(e)) 50 | return trueip 51 | 52 | 53 | def getIpFromWhatismyipaddress(site): 54 | headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/737.36(KHTML, like Gecke) Chrome/52.0.2743.82 Safari/537.36', 55 | 'Host': 'ip.tool.chinaz.com'} 56 | url = "https://whatismyipaddress.com//hostname-ip" 57 | data = { 58 | "DOMAINNAME": site, 59 | "Lookup IP Address": "Lookup IP Address" 60 | } 61 | trueip = None 62 | try: 63 | res = requests.post(url, headers=headers, data=data, timeout=5) 64 | soup = BeautifulSoup(res.text, 'html.parser') 65 | result = soup.find_all('span', class_="Whwtdhalf w15-0") 66 | for c in result: 67 | ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", c.text) 68 | if len(ip) != 0: 69 | trueip = ip[0] 70 | except Exception as e: 71 | print("查询" + site + " 时出现错误: " + str(e)) 72 | return trueip 73 | 74 | 75 | def getIpFromipapi(site): 76 | ''' 77 | return trueip: None or ip 78 | ''' 79 | headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/737.36(KHTML, like Gecke) Chrome/52.0.2743.82 Safari/537.36', 80 | 'Host': 'ip-api.com'} 81 | url = "http://ip-api.com/json/%s?lang=zh-CN" % (site) 82 | trueip = None 83 | for i in range(5): 84 | try: 85 | res = requests.get(url, headers=headers, timeout=5) 86 | res = json.loads(res.text) 87 | if(res["status"] == "success") and len(re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", res["query"])) == 1: 88 | trueip = res["query"] 89 | break 90 | except Exception as e: 91 | print("查询" + site + " 时出现错误: " + str(e)) 92 | return trueip 93 | -------------------------------------------------------------------------------- /github_host/github.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | ''' 4 | @Contact : liuyuqi.gov@msn.cn 5 | @Time : 2019/08/03 16:16:59 6 | @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved. 7 | @Desc : refeash github host everyday 8 | ''' 9 | import os 10 | import datetime 11 | from github_host import get_ip_utils 12 | from github_host.libs.json_conf import JsonConf 13 | 14 | 15 | class Github(object): 16 | 17 | def __init__(self): 18 | self.jsonConf = JsonConf() 19 | self.conf = self.jsonConf.load() 20 | self.sites = self.conf.get('sites') 21 | self.addr2ip = {} 22 | self.hostLocation = r"hosts" 23 | 24 | def dropDuplication(self, line): 25 | flag = False 26 | if "#*******" in line: 27 | return True 28 | for site in self.sites: 29 | if site in line: 30 | flag = flag or True 31 | else: 32 | flag = flag or False 33 | return flag 34 | 35 | def saveRouterosFile(self): 36 | ''' 应网友需求,导出一份 routeros 格式的hosts文件 ''' 37 | today = datetime.date.today() 38 | with open("hosts-routeros.txt", "w") as f: 39 | f.write("#*********************github " + 40 | str(today) + " update********************\n") 41 | f.write( 42 | "#******* get latest hosts: http://blog.yoqi.me/lyq/16489.html\n") 43 | for key in self.addr2ip: 44 | f.write("add address=" + self.addr2ip[key] + " name="+ key + "\n") 45 | 46 | # 更新host, 并刷新本地DNS 47 | def updateHost(self): 48 | today = datetime.date.today() 49 | for site in self.sites: 50 | trueip = get_ip_utils.getIpFromipapi(site) 51 | if trueip != None: 52 | self.addr2ip[site] = trueip 53 | print(site + "\t" + trueip) 54 | with open(self.hostLocation, "r") as f1: 55 | f1_lines = f1.readlines() 56 | with open("temphost", "w") as f2: 57 | for line in f1_lines: # 为了防止 host 越写用越长,需要删除之前更新的含有github相关内容 58 | if self.dropDuplication(line) == False: 59 | f2.write(line) 60 | f2.write("#*********************github " + 61 | str(today) + " update********************\n") 62 | f2.write( 63 | "#******* get latest hosts: http://blog.yoqi.me/lyq/16489.html\n") 64 | for key in self.addr2ip: 65 | f2.write(self.addr2ip[key] + "\t" + key + "\n") 66 | os.remove(self.hostLocation) 67 | os.rename("temphost", self.hostLocation) 68 | # os.system("ipconfig /flushdns") 69 | self.saveRouterosFile() 70 | -------------------------------------------------------------------------------- /github_host/libs/json_conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | ''' 4 | @Contact : liuyuqi.gov@msn.cn 5 | @Time : 2022/05/24 15:07:14 6 | @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved. 7 | @Desc : yaml util 8 | ''' 9 | import os 10 | import json 11 | 12 | 13 | class JsonConf: 14 | def __init__(self, config_path="conf/config.json"): 15 | self.config_path = config_path 16 | 17 | def save(self, data): 18 | with open(self.config_path, 'w') as json_file: 19 | json_file.write(json.dumps(data, indent=4)) 20 | 21 | def load(self): 22 | if not os.path.exists(self.config_path): 23 | with open(self.config_path, 'w') as json_file: 24 | pass 25 | with open(self.config_path, encoding="utf-8") as json_file: 26 | try: 27 | data = json.load(json_file) 28 | except Exception as e: 29 | if(str(e).index("utf-8-sig") > 0): 30 | with open(self.config_path, encoding="utf-8-sig") as json_file: 31 | data = json.load(json_file) 32 | return data 33 | else: 34 | print(e) 35 | return data 36 | 37 | def set(self, data_dict): 38 | json_obj = self.load() 39 | for key in data_dict: 40 | json_obj[key] = data_dict[key] 41 | self.save(json_obj) 42 | print(json.dumps(json_obj, indent=4)) 43 | 44 | def get(self, key, default_val=""): 45 | ''' 46 | 配置文件获取key对象的值,如果没有设置就返回默认值 47 | ''' 48 | try: 49 | result = self.load()[key] 50 | return result 51 | except Exception as e: 52 | print(e) 53 | return default_val 54 | 55 | def get(self, jsonData, key, default_val=""): 56 | try: 57 | return jsonData[key] 58 | except Exception as e: 59 | return default_val 60 | 61 | @staticmethod 62 | def get(jsonData, key, default_val=""): 63 | try: 64 | return jsonData[key] 65 | except Exception as e: 66 | return default_val 67 | -------------------------------------------------------------------------------- /hosts: -------------------------------------------------------------------------------- 1 | 2 | #*********************github 2025-06-08 update******************** 3 | #******* get latest hosts: http://blog.yoqi.me/lyq/16489.html 4 | 151.101.129.194 github.global.ssl.fastly.net 5 | 140.82.116.4 gist.github.com 6 | 185.199.111.133 gist.githubusercontent.com 7 | 185.199.111.154 github.githubassets.com 8 | 140.82.114.17 help.github.com 9 | 140.82.116.9 nodeload.github.com 10 | 185.199.109.133 raw.github.com 11 | 140.82.114.18 status.github.com 12 | 185.199.110.153 training.github.com 13 | 185.199.109.133 avatars.githubusercontent.com 14 | 185.199.109.133 avatars0.githubusercontent.com 15 | 185.199.108.133 avatars1.githubusercontent.com 16 | 185.199.111.133 avatars2.githubusercontent.com 17 | 185.199.109.133 avatars3.githubusercontent.com 18 | 185.199.110.133 avatars4.githubusercontent.com 19 | 185.199.110.133 avatars5.githubusercontent.com 20 | 185.199.108.133 avatars6.githubusercontent.com 21 | 185.199.110.133 avatars7.githubusercontent.com 22 | 185.199.108.133 avatars8.githubusercontent.com 23 | 185.199.109.133 favicons.githubusercontent.com 24 | 140.82.116.9 codeload.github.com 25 | 3.5.24.250 github-cloud.s3.amazonaws.com 26 | 52.217.174.137 github-com.s3.amazonaws.com 27 | 3.5.16.16 github-production-release-asset-2e65be.s3.amazonaws.com 28 | 3.5.28.115 github-production-user-asset-6210df.s3.amazonaws.com 29 | 3.5.27.203 github-production-repository-file-5c1aeb.s3.amazonaws.com 30 | 185.199.109.153 githubstatus.com 31 | 140.82.114.17 github.community 32 | 185.199.110.133 media.githubusercontent.com 33 | 185.199.111.133 camo.githubusercontent.com 34 | 185.199.109.133 raw.githubusercontent.com 35 | 185.199.108.133 cloud.githubusercontent.com 36 | 185.199.111.133 user-images.githubusercontent.com 37 | -------------------------------------------------------------------------------- /hosts-routeros.txt: -------------------------------------------------------------------------------- 1 | #*********************github 2025-06-08 update******************** 2 | #******* get latest hosts: http://blog.yoqi.me/lyq/16489.html 3 | add address=151.101.129.194 name=github.global.ssl.fastly.net 4 | add address=140.82.116.4 name=gist.github.com 5 | add address=185.199.111.133 name=gist.githubusercontent.com 6 | add address=185.199.111.154 name=github.githubassets.com 7 | add address=140.82.114.17 name=help.github.com 8 | add address=140.82.116.9 name=nodeload.github.com 9 | add address=185.199.109.133 name=raw.github.com 10 | add address=140.82.114.18 name=status.github.com 11 | add address=185.199.110.153 name=training.github.com 12 | add address=185.199.109.133 name=avatars.githubusercontent.com 13 | add address=185.199.109.133 name=avatars0.githubusercontent.com 14 | add address=185.199.108.133 name=avatars1.githubusercontent.com 15 | add address=185.199.111.133 name=avatars2.githubusercontent.com 16 | add address=185.199.109.133 name=avatars3.githubusercontent.com 17 | add address=185.199.110.133 name=avatars4.githubusercontent.com 18 | add address=185.199.110.133 name=avatars5.githubusercontent.com 19 | add address=185.199.108.133 name=avatars6.githubusercontent.com 20 | add address=185.199.110.133 name=avatars7.githubusercontent.com 21 | add address=185.199.108.133 name=avatars8.githubusercontent.com 22 | add address=185.199.109.133 name=favicons.githubusercontent.com 23 | add address=140.82.116.9 name=codeload.github.com 24 | add address=3.5.24.250 name=github-cloud.s3.amazonaws.com 25 | add address=52.217.174.137 name=github-com.s3.amazonaws.com 26 | add address=3.5.16.16 name=github-production-release-asset-2e65be.s3.amazonaws.com 27 | add address=3.5.28.115 name=github-production-user-asset-6210df.s3.amazonaws.com 28 | add address=3.5.27.203 name=github-production-repository-file-5c1aeb.s3.amazonaws.com 29 | add address=185.199.109.153 name=githubstatus.com 30 | add address=140.82.114.17 name=github.community 31 | add address=185.199.110.133 name=media.githubusercontent.com 32 | add address=185.199.111.133 name=camo.githubusercontent.com 33 | add address=185.199.109.133 name=raw.githubusercontent.com 34 | add address=185.199.108.133 name=cloud.githubusercontent.com 35 | add address=185.199.111.133 name=user-images.githubusercontent.com 36 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | ''' 4 | @Contact : liuyuqi.gov@msn.cn 5 | @Time : 2019/08/03 16:15:54 6 | @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved. 7 | @Desc : main function 8 | ''' 9 | import github_host 10 | 11 | if __name__ == '__main__': 12 | github_host.main() 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bs4 2 | requests --------------------------------------------------------------------------------