An open API service indexing awesome lists of open source software.

https://github.com/2ue/fast-github-hosts

Automatic GitHub Hosts generator with DoH, TCP speed test, and smart caching. Updates every 2 hours via GitHub Actions.
https://github.com/2ue/fast-github-hosts

Last synced: about 7 hours ago
JSON representation

Automatic GitHub Hosts generator with DoH, TCP speed test, and smart caching. Updates every 2 hours via GitHub Actions.

Awesome Lists containing this project

README

          

# GitHub Hosts 自动生成工具

> 自动获取GitHub所有域名的最优IP,生成hosts文件,加速GitHub访问
>
> 方法:多DNS源查询 + Ping+TCP测速

---

## ✨ 特性

- 🚀 **自动DNS查询**:并发查询4个DNS服务器(Cloudflare、Google、阿里、114)
- ⚡ **智能测速**:Ping + TCP双重测速,综合评分选择最快IP
- 📋 **完整域名**:涵盖49个核心GitHub域名(可扩展至120+)
- 🔄 **并发处理**:多线程并发,快速生成
- 📊 **详细输出**:实时显示处理进度和测速结果

---

## 📦 安装依赖

```bash
pip install dnspython
```

---

## 🚀 快速使用

### 1. 生成hosts文件

```bash
python3 generate_github_hosts.py
```

### 2. 应用hosts文件

#### Linux/Mac

```bash
# 备份原hosts
sudo cp /etc/hosts /etc/hosts.bak

# 应用新hosts
sudo cp ultra_hosts /etc/hosts

# 刷新DNS
sudo systemd-resolve --flush-caches # Linux
sudo killall -HUP mDNSResponder # Mac
```

#### Windows

```powershell
# 以管理员身份运行PowerShell

# 备份原hosts
copy C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts.bak

# 应用新hosts(手动复制ultra_hosts内容到hosts文件)

# 刷新DNS
ipconfig /flushdns
```

---

## 📋 域名列表

脚本包含 **141个完整域名**,涵盖:

| 分类 | 数量 | 说明 |
|------|------|------|
| 核心服务 | 12 | github.com、api.github.com等 |
| CDN静态资源 | 5 | github.githubassets.com等 |
| UserContent | 21 | raw.githubusercontent.com、objects等 |
| 包管理器 | 12 | ghcr.io、npm、docker、pypi等 |
| AWS S3存储 | 5 | github-cloud.s3.amazonaws.com等 |
| Copilot | 6 | githubcopilot.com、api等 |
| Actions核心 | 9 | pipelines、vstoken、broker等 |
| Actions Pipelines | 28 | pipelinesghubeus系列 |
| Actions Runners | 12 | runnerghubeus系列 |
| Azure Blob - Actions | 20 | productionresultssa系列 |
| Azure Blob - 包管理 | 4 | maven/npm/nuget/rubygems blob |
| 安全认证 | 3 | tuf-repo、fulcio等 |
| 开发工具 | 1 | vscode.dev |
| **总计** | **141** | **完整覆盖所有GitHub服务** |

详细域名列表请查看 [DOMAINS.md](./DOMAINS.md)

---

## ⚙️ 配置说明

编辑 `generate_github_hosts.py` 可自定义配置:

```python
# DNS服务器列表
DNS_SERVERS = [
'1.1.1.1', # Cloudflare
'8.8.8.8', # Google
'223.5.5.5', # 阿里
'114.114.114.114', # 114
]

# 测速配置
PING_COUNT = 2 # Ping次数
TCP_TIMEOUT = 2 # TCP超时(秒)
TCP_PORT = 443 # 测试端口
MAX_WORKERS = 10 # 最大并发数
```

---

## 📊 运行示例

```
======================================================================
🚀 GitHub Hosts 自动生成工具 - Ultra版本
======================================================================
📋 域名总数: 141
🌐 DNS服务器: 1.1.1.1, 8.8.8.8, 223.5.5.5, 114.114.114.114
⚡ 测速方法: Ping + TCP
======================================================================

🔍 正在处理: github.com
📡 找到 3 个IP: 20.205.243.166, 140.82.114.4, 140.82.113.3
⚡ 20.205.243.166: 45.32ms
⚡ 140.82.114.4: 156.78ms
⚡ 140.82.113.3: 158.92ms
✅ 最快IP: 20.205.243.166 (45.32ms)

🔍 正在处理: api.github.com
📡 找到 2 个IP: 20.205.243.168, 140.82.113.5
⚡ 20.205.243.168: 43.21ms
⚡ 140.82.113.5: 157.45ms
✅ 最快IP: 20.205.243.168 (43.21ms)

...

======================================================================
✅ Hosts文件已生成: ultra_hosts
✅ 成功获取: 141/141 个域名
⏱️ 总耗时: 120.45 秒
======================================================================
```

---

## 🎯 高级用法

### 扩展域名列表

如果你需要更多域名(如完整的Actions支持),编辑 `GITHUB_DOMAINS` 列表:

```python
GITHUB_DOMAINS = [
# ... 原有域名 ...

# 添加Actions额外域名
'vstoken.actions.githubusercontent.com',
'broker.actions.githubusercontent.com',
'launch.actions.githubusercontent.com',
# ... 更多域名见DOMAINS.md ...
]
```

### 定时自动更新

Linux/Mac使用crontab定时执行:

```bash
# 每天凌晨3点自动更新
0 3 * * * cd /path/to/github-hosts && python3 generate_github_hosts.py && sudo cp ultra_hosts /etc/hosts && sudo systemd-resolve --flush-caches
```

---

## 🔧 故障排除

### DNS查询失败

- **原因**:DNS服务器被墙或超时
- **解决**:更换DNS服务器,或增加超时时间

### 测速失败

- **原因**:防火墙阻止ICMP或TCP连接
- **解决**:
- 临时关闭防火墙测试
- 调整TCP端口(默认443)
- 增加超时时间

### 所有IP都很慢

- **原因**:你的网络到GitHub服务器延迟较高
- **解决**:
- 尝试不同时间段运行
- 考虑使用代理或VPN
- 检查本地网络质量

---

## 📝 文件说明

```
github-hosts/
├── generate_github_hosts.py # 主脚本
├── DOMAINS.md # 完整域名列表文档
├── README.md # 使用说明
└── ultra_hosts # 生成的hosts文件(运行后)
```

---

## 🤝 贡献

欢迎提交Issue和PR!

---

## 📄 许可证

MIT License

---

## ⚠️ 免责声明

本工具仅用于加速GitHub访问,不保证100%成功。使用本工具修改hosts文件造成的任何问题,作者不承担责任。