GitHub DNS Helper 你是 GitHub DNS 修复助手,专精于解决 GitHub 访问问题。 使用方法 自动修复 直接运行脚本: 重要提示: - 首次使用需要配置 hosts 文件权限(只需一次) - 修改 hosts 文件需要管理员权限,请根据操作系统执行以下命令: 检测操作系统: 输出结果: 、 (macOS) 或 macOS: Linux: Windows: - 无需配置权限 - 直接以管理员身份运行命令提示符或 PowerShell 即可 ⚠️ 此操作建议由用户在系统终端中自己执行 执行后,脚本将不再需要 sudo 权限,可以免密码运行 仅检查连接状态 使用自定义 hosts 源 查看帮助 ---

)\n backup_files = sorted([f for f in os.listdir(BACKUP_DIR) if backup_pattern.match(f)])\n if len(backup_files) > 5:\n files_to_delete = backup_files[:-5]\n for old_file in files_to_delete:\n old_backup_path = os.path.join(BACKUP_DIR, old_file)\n try:\n os.remove(old_backup_path)\n print(f\" 🗑️ 已删除旧备份: {old_file}\")\n except PermissionError:\n print(f\" ⚠️ 删除备份失败 {old_file}: 权限不足\")\n except Exception as e:\n print(f\" ⚠️ 删除备份失败 {old_file}: {e}\")\n except Exception as e:\n print(f\" ⚠️ 清理备份失败: {e}\")\n except PermissionError:\n print_status(f\"备份失败:权限不足,请以管理员身份运行\", False)\n sys.exit(1)\n except Exception as e:\n print_status(f\"备份失败: {e}\", False)\n sys.exit(1)\n\n print(\"\\n🗑️ 步骤 2: 清理旧的 GitHub hosts...\")\n try:\n with open(HOSTS_FILE, \"r\", encoding=\"utf-8\") as f:\n current_hosts = f.read()\n except FileNotFoundError:\n print_status(\"hosts 文件不存在\", False)\n sys.exit(1)\n except Exception as e:\n print_status(f\"读取 hosts 文件失败: {e}\", False)\n sys.exit(1)\n\n old_section_start = current_hosts.find(MARKER_START)\n old_section_end = current_hosts.find(MARKER_END)\n\n if old_section_start != -1 and old_section_end != -1:\n cleaned_hosts = current_hosts[:old_section_start] + current_hosts[old_section_end + len(MARKER_END):]\n else:\n cleaned_hosts = current_hosts\n\n cleaned_hosts = cleaned_hosts.rstrip() + \"\\n\"\n print_status(\"已清理旧的 GitHub hosts\")\n\n hosts_urls = get_hosts_urls(args)\n success = False\n \n for attempt, url in enumerate(hosts_urls, 1):\n print(f\"\\n📥 步骤 3: 获取最新 hosts...\")\n print(f\" 尝试 ({attempt}/{len(hosts_urls)}): {url}\")\n \n github_hosts = fetch_single_host(url)\n if not github_hosts:\n print_status(f\"从 {url} 获取失败,尝试下一个...\", False)\n continue\n \n print(f\"找到 GitHub hosts ({len(github_hosts.splitlines())} 条记录)\")\n\n print(\"\\n✍️ 步骤 4: 写入新的 hosts...\")\n timestamp = datetime.datetime.now().astimezone().strftime(\"%Y-%m-%dT%H:%M:%S%z\")\n timestamp = timestamp[:-2] + \":\" + timestamp[-2:]\n final_hosts = cleaned_hosts + \"\\n\" + MARKER_START + \"\\n\"\n final_hosts += github_hosts + \"\\n\"\n final_hosts += f\"# Update time: {timestamp}\\n\"\n final_hosts += f\"# Update url: {url}\\n\"\n final_hosts += MARKER_END + \"\\n\"\n\n try:\n with open(HOSTS_FILE, \"w\", encoding=\"utf-8\") as f:\n f.write(final_hosts)\n print_status(\"已写入 hosts 文件\")\n except PermissionError:\n print_status(\"写入 hosts 文件失败:权限不足,请以管理员身份运行\", False)\n sys.exit(1)\n except Exception as e:\n print_status(f\"写入 hosts 文件失败:{e}\", False)\n sys.exit(1)\n\n print(\"\\n🔄 步骤 5: 刷新 DNS 缓存...\")\n dns_success = False\n \n if IS_WINDOWS:\n returncode, stdout, stderr = run_command(\"ipconfig /flushdns\", sudo=False)\n dns_success = returncode == 0\n elif IS_MACOS:\n returncode, stdout, stderr = run_command(\"dscacheutil -flushcache\", sudo=False)\n returncode2, stdout2, stderr2 = run_command(\"killall -HUP mDNSResponder\", sudo=False)\n dns_success = returncode == 0 or returncode2 == 0\n elif IS_LINUX:\n returncode, stdout, stderr = run_command(\"systemd-resolve --flush-caches\", sudo=True)\n if returncode != 0:\n returncode, stdout, stderr = run_command(\"nscd -i hosts\", sudo=True)\n if returncode != 0:\n returncode, stdout, stderr = run_command(\"rndc flush\", sudo=True)\n dns_success = returncode == 0\n else:\n print(\"⚠️ 未知平台,跳过 DNS 缓存刷新\")\n\n if dns_success:\n print_status(\"DNS 缓存已刷新\")\n else:\n print_status(f\"刷新 DNS 失败\", False)\n\n print(\"\\n🏓 步骤 6: 验证连接...\")\n all_success, success_count, total_count = check_connectivity(ping_count=3, check_http=True, show_details=True)\n\n if all_success:\n success = True\n break\n else:\n print(f\"\\n⚠️ 当前 hosts 源修复不完全成功,尝试下一个源...\")\n continue\n \n print(\"\\n\" + \"=\" * 50)\n if success:\n print(\"✨ 修复完成!所有域名连接正常\")\n else:\n print(\"⚠️ 修复完成,但连接仍有问题,请检查网络设置\")\n print(\"=\" * 50)\n\n\nif __name__ == \"__main__\":\n main()\n","content_type":"text/x-python; charset=utf-8","language":"python","size":13286,"content_sha256":"af78785dc612c12b091ac0a457cc4cacaa8e5fcf77f2ba65b1d5faee2f1767e0"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"GitHub DNS Helper","type":"text"}]},{"type":"paragraph","content":[{"text":"你是 GitHub DNS 修复助手,专精于解决 GitHub 访问问题。","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"使用方法","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"自动修复","type":"text"}]},{"type":"paragraph","content":[{"text":"直接运行脚本:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python3 {{skill_path}}/scripts/fix_github_dns.py","type":"text"}]},{"type":"paragraph","content":[{"text":"重要提示:","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"首次使用需要配置 hosts 文件权限(只需一次)","type":"text","marks":[{"type":"strong"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"修改 hosts 文件需要管理员权限,请根据操作系统执行以下命令:","type":"text"}]},{"type":"paragraph","content":[{"text":"检测操作系统:","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python3 -c \"import platform; print(platform.system())\"","type":"text"}]},{"type":"paragraph","content":[{"text":"输出结果:","type":"text"},{"text":"Windows","type":"text","marks":[{"type":"code_inline"}]},{"text":"、","type":"text"},{"text":"Darwin","type":"text","marks":[{"type":"code_inline"}]},{"text":" (macOS) 或 ","type":"text"},{"text":"Linux","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"macOS:","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"sudo chown $(whoami):staff /etc/hosts\nsudo chmod 644 /etc/hosts","type":"text"}]},{"type":"paragraph","content":[{"text":"Linux:","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"sudo chown $(whoami):$(whoami) /etc/hosts\nsudo chmod 644 /etc/hosts","type":"text"}]},{"type":"paragraph","content":[{"text":"Windows:","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"无需配置权限","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"直接以管理员身份运行命令提示符或 PowerShell 即可","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"⚠️ ","type":"text"},{"text":"此操作建议由用户在系统终端中自己执行","type":"text","marks":[{"type":"strong"}]},{"text":" 执行后,脚本将不再需要 sudo 权限,可以免密码运行","type":"text"}]}]}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"仅检查连接状态","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python3 {{skill_path}}/scripts/fix_github_dns.py --check","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"使用自定义 hosts 源","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python3 {{skill_path}}/scripts/fix_github_dns.py -u \"https://your-custom-url.com/hosts\"","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"查看帮助","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"python3 {{skill_path}}/scripts/fix_github_dns.py --help","type":"text"}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"github-dns-helper","author":"@skillopedia","source":{"stars":1,"repo_name":"awsome_skills","origin_url":"https://github.com/thincher/awsome_skills/blob/HEAD/github-dns-helper/SKILL.md","repo_owner":"thincher","body_sha256":"0b35ccae6de0309ed6536632a2f63f38e702bc35214f58bdb8d95061fc042631","cluster_key":"dd7fde13c465cdcf0e0af00a34fe7552c642aa31e78d73a00f258a6d75ce9472","clean_bundle":{"format":"clean-skill-bundle-v1","source":"thincher/awsome_skills/github-dns-helper/SKILL.md","attachments":[{"id":"59473f1c-5170-5c08-8e0f-5e05f4250efe","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/59473f1c-5170-5c08-8e0f-5e05f4250efe/attachment.py","path":"scripts/fix_github_dns.py","size":13286,"sha256":"af78785dc612c12b091ac0a457cc4cacaa8e5fcf77f2ba65b1d5faee2f1767e0","contentType":"text/x-python; charset=utf-8"}],"bundle_sha256":"88f05fd792415198d9f26e8c554e82d16266417da3def138084aafaa27df53c8","attachment_count":1,"text_attachments":1,"attachment_storage":"skillopedia-attachments-v1","binary_attachments":0,"excluded_attachments":[]},"cluster_size":1,"skill_md_path":"github-dns-helper/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"integrations-apis","category_label":"Integrations"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"integrations-apis","import_tag":"clean-skills-v1","description":"GitHub DNS 修复助手。解决 GitHub 访问问题。当用户遇到 GitHub 无法访问、DNS 解析失败、连接超时等问题时使用此技能。"}},"renderedAt":1782979522401}

GitHub DNS Helper 你是 GitHub DNS 修复助手,专精于解决 GitHub 访问问题。 使用方法 自动修复 直接运行脚本: 重要提示: - 首次使用需要配置 hosts 文件权限(只需一次) - 修改 hosts 文件需要管理员权限,请根据操作系统执行以下命令: 检测操作系统: 输出结果: 、 (macOS) 或 macOS: Linux: Windows: - 无需配置权限 - 直接以管理员身份运行命令提示符或 PowerShell 即可 ⚠️ 此操作建议由用户在系统终端中自己执行 执行后,脚本将不再需要 sudo 权限,可以免密码运行 仅检查连接状态 使用自定义 hosts 源 查看帮助 ---