# fetch-github-hosts **Repository Path**: devved/fetch-github-hosts ## Basic Information - **Project Name**: fetch-github-hosts - **Description**: No description available - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-10-27 - **Last Updated**: 2024-10-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 简体中文 | [English](./README_EN.md)

Fetch GitHub Hosts

![LOGO](assets/public/logo.png) `fetch-github-hosts` 是主要为解决研究及学习人员访问 `Github` 过慢或其他问题而提供的 `Github Hosts` 同步工具 [![Release](https://img.shields.io/github/v/release/Licoy/fetch-github-hosts.svg?logo=git)](https://github.com/Licoy/fetch-github-hosts) [![Build Linux & Windows](https://github.com/Licoy/fetch-github-hosts/workflows/Build%20for%20Linux%20&%20Windows/badge.svg)](https://github.com/Licoy/fetch-github-hosts) [![Build MacOS](https://github.com/Licoy/fetch-github-hosts/workflows/Build%20for%20MacOS/badge.svg)](https://github.com/Licoy/fetch-github-hosts)
## 原理 此项目是通过部署此项目本身的服务器来获取 `github.com` 的 `hosts`,而不是通过第三方ip地址接口来进行获取,例如 `ipaddress.com` 等。 ## 使用方法 ### 图形化界面 到 [Releases](https://github.com/Licoy/fetch-github-hosts/releases) 中下载您的系统版本(目前支持`Windows`/`Linux`/`MacOS` ) 下载完成解压`tar.gz`压缩包,运行对应平台的执行文件即可运行( ⚠️ 注意:Linux下需要用`sudo`进行启动,Windows和MacOS会自动进行提权操作。) #### 客户端模式 ![client](assets/public/docs/client.png) #### 客户端启动 ![client-start](assets/public/docs/client-start.png) #### 客户端hosts源选择 ![client-select](assets/public/docs/client-select.png) #### 客户端hosts源自定义 ![client-custom](assets/public/docs/client-custom.png) #### 服务端模式 ![server](assets/public/docs/server.png) ### 命令行终端 到 [Releases](https://github.com/Licoy/fetch-github-hosts/releases) 中下载您的系统版本(目前支持`Windows`/`Linux`/`MacOS` ) #### 参数 | 参数名 | 缩写 | 默认值 | 必填 | 描述 | |------------|-----|--------------------------------------|-----|------------------------------------| | `mode` | `m` | 无 | 是 | 启动模式 `server(服务端)` / `client(客户端)` | | `interval` | `i` | 60 | 否 | 获取记录值间隔(分钟) | | `port` | `p` | 9898 | 否 | 服务模式监听端口以访问HTTP服务 | | `url` | `u` | `https://hosts.gitcdn.top/hosts.txt` | 否 | 客户端模式远程hosts获取链接 | | `lang` | `l` | `zh-CN` | 否 | 界面语言 | #### 启动客户端: > 注意: > > Linux下需要使用`sudo`运行; > > Windows和MacOS会自动进行提权操作。 - 直接运行 ```bash # Linux/Macos sudo fetch-github-hosts -m=client # Windows fetch-github-hosts.exe -m=client ``` - 自定义获取时间间隔 ```bash # Linux/Macos(10分钟获取一次) sudo fetch-github-hosts -i=10 # Windows(10分钟获取一次) fetch-github-hosts.exe -i=10 ``` - 自定义获取链接 ```bash # Linux/Macos sudo fetch-github-hosts -u=http://127.0.0.1:9898/hosts.json # Windows fetch-github-hosts.exe -u=http://127.0.0.1:9898/hosts.json ``` #### 启动服务端: - 直接运行 ```bash # Linux/Macos fetch-github-hosts -m=server # Windows fetch-github-hosts.exe -m=server ``` - 自定义监听端口 ```bash # Linux/Macos fetch-github-hosts -m=server -p=6666 # Windows fetch-github-hosts.exe -m=server -p=6666 ``` ### 手动 #### 添加hosts 访问 [https://hosts.gitcdn.top/hosts.txt](https://hosts.gitcdn.top/hosts.txt) , 将其全部内容粘贴到你的hosts文件中,即可。 - `Linux / MacOS` hosts路径:`/etc/hosts` - `Windows` hosts路径:`C:\Windows\System32\drivers\etc\hosts` #### 刷新生效 - `Linux`: `/etc/init.d/network restart` - `Windows`: `ipconfig /flushdns` - `Macos`: `sudo killall -HUP mDNSResponder` #### Unix/Linux 一键使用 ```shell sed -i "/# fetch-github-hosts begin/Q" /etc/hosts && curl https://hosts.gitcdn.top/hosts.txt >> /etc/hosts ``` > 提示:可以设置crontab定时任务定时获取更新即可,解放双手! ## 私有部署 下载最新的发行版(到 [Releases](https://github.com/Licoy/fetch-github-hosts/releases) 进行下载) ,并选择您的系统对应版本,直接以服务模式运行即可:`fetch-github-hosts -m=server -p=9898`,会自动监听`0.0.0.0:9898`,您可以直接浏览器访问 `http://127.0.0.1:9898` 以访问您自定义服务。 (具体方法可参见【启动服务端】小节详细说明) > 注意:因网络影响,尽量部署到海外服务器节点! ## 趋势 [![Stargazers over time](https://starchart.cc/Licoy/fetch-github-hosts.svg)](https://starchart.cc/Licoy/fetch-github-hosts) ## 开源协议 [GPL 3.0](https://github.com/Licoy/fetch-github-hosts/blob/main/LICENSE)