1 Star 0 Fork 1

Mr.成/劳资实在受不了github的龟速了

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
update_hosts.js 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
红日初升 提交于 2021-05-03 13:59 . update
const dns = require("dns")
const handleHosts = require("./handleHosts")
const front = "#官网:47.108.77.223"
const rear = "#当前版本更新于:" + new Date().toLocaleString("zh-CN") + "\n#end"
const domains = [
/*
* 这些地址来源于github520,
* 但有些地址可能会返回0.0.0.0,
* 但这不是程序自身的问题,
* 而是防火墙的问题,
* 尚未得到解决
*/
"github.githubassets.com",
"central.github.com",
"desktop.githubusercontent.com",
"assets-cdn.github.com",
"camo.githubusercontent.com",
"github.map.fastly.net",
"github.global.ssl.fastly.net",
"gist.github.com",
"github.io",
"github.com",
"api.github.com",
"raw.githubusercontent.com",
"user-images.githubusercontent.com",
"favicons.githubusercontent.com",
"avatars5.githubusercontent.com",
"avatars4.githubusercontent.com",
"avatars3.githubusercontent.com",
"avatars2.githubusercontent.com",
"avatars1.githubusercontent.com",
"avatars0.githubusercontent.com",
"avatars.githubusercontent.com",
"codeload.github.com",
"github-cloud.s3.amazonaws.com",
"github-com.s3.amazonaws.com",
"github-production-release-asset-2e65be.s3.amazonaws.com",
"github-production-user-asset-6210df.s3.amazonaws.com",
"github-production-repository-file-5c1aeb.s3.amazonaws.com",
"githubstatus.com",
"github.community",
"media.githubusercontent.com"
]
const handleError = require("./handleError")
const jsonToHosts = (data) => {
let result = ""
for (let key in data) {
const value = data[key] //遍历对象时的值
result += "\n" + value + " " + key
}
return result
}
const getHosts = () => {
const hosts = {}
let resultNum = 0
for (let i of domains) {
dns.resolve(i, (err, address) => {
if (err) {
handleError(err)
} else if (address) {
if (address.length > 1) {
for (let j of address) {
if (j !== "0.0.0.0") {
address = j
}
}
} else {
address = address[0]
}
hosts[i] = address
}
resultNum++
})
}
const polling = () => {
if (resultNum === domains.length) {
const resultHosts = front + "\n\n" + jsonToHosts(hosts) + "\n\n" + rear //将结果加上前置文本与后缀文本
handleHosts(resultHosts)
return resultHosts
} else {
setTimeout(polling, 1000) //轮询
}
}
polling()
}
module.exports = getHosts
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lchengneu/github-hosts.git
git@gitee.com:lchengneu/github-hosts.git
lchengneu
github-hosts
劳资实在受不了github的龟速了
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385