← 返回
未分类

github改hosts文件加速skill,仅针对windows

Optimize GitHub access speed on Windows by finding the fastest IPs and updating the hosts file to reduce latency.
通过在Windows上寻找最快的IP并更新hosts文件来优化GitHub访问速度,降低延迟。
vay-qz vay-qz 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 296
下载
💾 0
安装
1
版本
#latest

概述

GitHub Hosts Optimizer

On Windows, directly modify C:\Windows\System32\drivers\etc\hosts to map GitHub domains to faster IPs.

Workflow

  1. Resolve GitHub IPs using nslookup:
    • github.com
    • api.github.com
    • objects.githubusercontent.com
  1. Ping each IP to measure latency (ping -n 3 )
  1. Select fastest IP (lowest average latency)
  1. Update hosts file with entries:

```

github.com

api.github.com

github.com (duplicate for reliability)

```

  1. Flush DNS cache:

```

ipconfig /flushdns

```

PowerShell Script

$hostsPath = "$env:SystemRoot\System32\drivers\etc\hosts"
$domains = @("github.com", "api.github.com", "objects.githubusercontent.com")

# Resolve IPs
$ips = @{}
foreach ($domain in $domains) {
    $result = nslookup $domain 2>$null
    $ips[$domain] = ($result | Select-String -Pattern "Addresses:" -Context 0,10 | ForEach-Object { $_.Context.PostContext }) -replace '\s+', '' | Where-Object { $_ -match '^\d+\.\d+\.\d+\.\d+$' }
}

# Ping each IP and find fastest
$results = @()
foreach ($ip in ($ips.Values | Select-Object -Unique)) {
    $avg = (ping -n 3 $ip | Select-String -Pattern "平均").ToString() -replace '.*= (\d+)ms.*', '$1'
    if ($avg) { $results += [PSCustomObject]@{ IP = $ip; Avg = [int]$avg } }
}
$fastest = ($results | Sort-Object Avg | Select-Object -First 1).IP

# Update hosts
$entry = "$fastest github.com`n$fastest api.github.com"
$current = Get-Content $hostsPath -Raw -ErrorAction SilentlyContinue
if ($current -notmatch "github\.com") {
    Add-Content -Path $hostsPath -Value $entry
} else {
    $updated = $current -replace "[\d\.]+\s+github\.com`n?[\d\.]+\s+api\.github\.com", $entry
    Set-Content -Path $hostsPath -Value $updated
}

# Flush DNS
ipconfig /flushdns | Out-Null
Write-Host "Done! Fastest IP: $fastest"

Key Notes

  • Hosts file requires Administrator privileges to modify
  • If direct edit fails, output the entry and instruct user to manually add it
  • The fastest IP may change over time; re-run when GitHub access slows again

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 22:30 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 30,957
it-ops-security

Tmux

steipete
通过发送按键和抓取窗格输出,远程控制交互式 CLI 的 tmux 会话。
★ 46 📥 29,545
it-ops-security

1password

steipete
设置和使用 1Password CLI (op)。适用于:安装 CLI、启用桌面应用集成、登录(单/多账户)、通过 op 读取/注入/运行密钥。
★ 53 📥 31,644