3

principle

Modify the local host file to speed up access to github.

How to obtain the github proxy ip address in China?
I found this website: http://ping.chinaz.com/github.com

The specific idea is the same as the above website, the loop request interface to obtain the delay of the computer room in various places, and then compare the computer room with the lowest delay, get the ip, then modify the local Host file, go.

Get request interface

to this website 1609a6ac107373 http://ping.chinaz.com/github.com to find similarities soon. The interface is as follows:

get http://ping.chinaz.com/iframe.ashx

Among them, the most critical is guid, just copy the rest of the parameters.

Regarding the guid, right-click the source code and find that the guid is all under the element with speedlist
Get the guid of all computer rooms through the following code

var a = Array.from($0.children).map(v => v.getAttribute('id'))
copy(a)

Final data

[
"4daa81e2-f397-4cde-bf74-b2bee84a4ea5",
  "95b30a9e-f797-46ae-b9ef-268692caddf6",
  "eeb78862-50d4-4823-94f2-6de143374a27",
  "403d18aa-9a0f-4d3c-b175-f4a10683deb9",
  "32574c06-d0fc-4709-8fc9-fce30596efd3",
  "c665eba1-e4a0-4da3-a438-404768bb5fd6",
  "b81dffbf-3644-43a3-bf29-099816488ba2",
  "252167a8-eaeb-491b-a4f3-319d25680f48",
  "db8eb6ed-734e-4747-a526-d6c8b408acb5",
  "aaeb0b79-c13c-48b8-abc8-ae8ce1ec7f65",
  "4a40427f-502e-4a85-8752-980f2d8bbae1",
  "0003d32b-8585-4480-b0ea-dd0a10768dd2",
  "0209986e-259b-4817-9d17-2418bb5b0756",
  "e6a3a9b7-2088-41be-bf1d-6a25276ab1ed",
  "6a3749de-aa34-4b7f-96c8-f28b9a32238b",
  "8fbd45ea-7fe2-43f5-84aa-cd3921475732",
  "efa326df-41dd-4c7f-af5e-bd7572658d82",
  "1f430ff0-eae9-413a-af2a-1c2a8986cff0",
  "ca6e017e-17b8-45eb-94b3-a408b8b79f1c",
  "4d7637d7-4950-4b79-9741-c397789bcf05",
  "0f885910-80d6-4f77-8f4f-3d90d8779d17",
  "fcb3c928-222c-45dc-b2cd-85508e385b65",
  "74cb6a5c-b044-49d0-abee-bf42beb6ae05",
  "604e79e8-f0ad-40a3-ad30-fc2c55b78943",
  "5802da93-4e05-4932-9bc6-20d5d75b7af5",
  "61ceba20-2cb1-4482-9e48-acbe876bd3ba",
  "7f46f5c9-d719-4886-b3c0-6b6427908791",
  "415ce02c-b3e9-4cad-adbd-baab32d63edc",
  "0e519c9d-dab8-480c-a372-c72480dd133a",
  "df8bdd7a-b928-41f8-959f-d0d56fadea64",
  "17d812b5-ced1-4717-8669-51ce10615682",
  "5d20130d-75e0-481e-a651-c3da8656a3b3",
  "766a3283-4add-438d-a5bb-e8b6cef139c3",
  "2140cc66-e5ea-4f56-981a-8f044a98c92a",
  "8d8e4cbb-10de-4573-bb56-1dd7e36feaf3",
  "36317cda-2716-49e0-9cd0-4baaa0cacaf3",
  "56d53df5-2784-4b70-b268-6594a216109b",
  "14ef4fcf-3712-4971-9c24-0d1657751022",
  "ec83c2ca-95ec-40ba-aabe-a9b6f3da8fff",
  "24ad8183-b682-4c00-8d58-b73b47d558ca",
  "0d3fd0b2-1255-4e5d-b94e-717569d2e8bd",
  "96bcf0f8-dccc-4a66-9ce1-a5107b8779a8",
  "74c25181-4087-459a-8035-67278afaa2f1",
  "df61b0a8-f88e-4959-9e4e-c33101f4de2e",
  "b615642c-ac86-4322-9fbe-4bd79e175a99",
  "9cd12aba-b71d-4cfd-92a4-4447745ee9e1",
  "f3edbd07-fc92-4333-8626-4f6f4ce49b0b",
  "0fb19ea5-4a8e-49ec-b248-59dabf586245",
  "9bc90d67-d208-434d-b680-294ae4288571",
  "0caa7b64-4a66-4de2-b4d9-0f7d537cd8ae",
  "942de632-7962-41e5-961b-c7ad98b31c5a",
  "fb715e9d-f578-41bd-b95f-75cc3fe69cf2",
  "5713f157-3378-495a-9c55-7172187e9f36",
  "316c5129-231d-4494-a81f-e49d14de9a81",
  "3a8de27a-c93e-4f97-9b67-f2b5b2028eb8",
  "3bafbbb2-dc57-4de7-8ef6-20402b881dbe",
  "5074fb13-4ab9-4f0a-87d9-f8ae51cb81c5",
  "47b7ab69-0008-4dae-8d99-54f7038f1510",
  "9280a6f4-f3c6-4173-a77d-c2bdaac3e709",
  "07f2f1cc-8414-4557-a8c1-27750a732f16",
  "012834d4-5a15-4a90-9520-8515e558873f",
  "6c84b028-554b-49f4-87bd-4f15f3eed735",
  "eb7215a6-7f0e-4bf7-89fe-ec0e7ee9f32c",
  "19ef9d71-e0cb-4b79-a416-8fd670f6e7ca",
  "945fcfae-276a-4e42-9133-4d47d2999b08",
  "ea551b59-2609-4ab4-89bc-14b2080f501a",
  "a936bb02-6b19-4da5-9c82-e8bb68fcfbea",
  "703e401a-1e50-4bda-9c82-b1ca883e3bbf",
  "2805fa9f-05ea-46bc-8ac0-1769b782bf52",
  "b698f5c4-0c88-4ae4-b123-ef57293ce442",
  "9c137190-5a57-4ef5-be4b-b9add998ad52",
  "0bf6e659-226e-40b1-b605-962929e9fba8",
  "4d462057-4581-4ae1-974d-ca7ca019e700",
  "e91e73db-703d-464d-a82a-1e8286a19cb1",
  "a1fa84e1-aeb5-4909-aac8-d6f0d7e45456",
  "f8205979-1951-4f20-a66e-2f2ca97cf75b",
  "11bd620a-7456-4835-9129-038eaa9fa8b9",
  "dc440a55-1148-480f-90a7-9d1e0269b682",
  "3ce7a84d-191b-49a2-81a6-e32bbe2c06a0",
  "8c0b720b-e1a1-4422-a948-e8d7ec7e4906",
  "9365c01e-163f-4f07-b569-a9302b685c30",
  "8ebdf782-2203-4bc2-9774-68fe0d3691c8",
  "5bea1430-f7c2-4146-88f4-17a7dc73a953",
  "6e5e03b3-d8d6-48bc-a87a-033f7c877b33",
  "12b16bb6-d42d-4296-a394-b96b22bca9c3",
  "6305bac1-7adb-48cf-aff2-d3ac2dd65dde",
  "8fef9cd0-af0b-4beb-b0b0-37388c74a2ae",
  "d434f9dd-c862-47e0-89cf-3633aa061509",
  "38ecaef6-76e4-4030-bd7f-af9e6240f4b6",
  "483bad95-d9a8-4026-87f4-7a56501bf5fd",
  "87c200e0-0059-479f-8103-e9e504f735d0",
  "bd3b89bd-aeec-4079-8c08-a86770abb830",
  "cb22befe-58f9-45f6-a246-4ad66bcfa448",
  "08117724-8437-4ebb-88ae-93e50f660867",
  "cb9069aa-c897-4f27-bc36-988da8f4cb03",
  "9d5f55d6-ad1a-4efb-b368-c7de4b7005c5",
  "6c5f2077-b898-4918-86b0-9ab82273eea6",
  "040d7a4f-3c04-462f-9e96-2bf629af4a08",
  "cdcf3a45-8366-4ab4-ae80-75eb6c1c9fca",
  "91937e5b-1db0-47b5-b114-c9294694f377",
  "c1b98ee7-8584-4e98-8e6d-049a633b6bdf",
  "eac78784-07a1-4869-be7c-3870a8dcebfc",
  "7b578630-b705-42dc-936f-8d4703b955ac",
  "e33f289c-f401-449b-a135-e654e597b150",
  "737831b4-95e1-445f-a981-c1333faf88bd",
  "39bed414-9402-4266-aa9a-8252e958558f",
  "54a02700-5812-4ec8-8d24-c4276c7eb080",
  "5c02bccc-ae5c-45ef-9204-b3055f985e20",
  "95d0626d-dc85-48c0-b3a9-e656811d3028",
  "2b0dc147-1f6c-405c-b91f-faff417cf1da",
  "b2bbe313-d66d-47a3-ace2-d1229da5c28c",
  "774af056-e15d-4689-83f7-e5067a0c5512",
  "80a828bd-19ed-48c3-a035-e69f6468da03",
  "5fb9012d-b47c-4087-84a2-0b0dfa8c94ab",
  "e11f1b36-2995-413c-90bb-9f3afff8caed",
  "38806ef7-4638-4808-96e4-85047dfa5853",
  "53e79941-312c-4343-8739-6be3cd105805",
  "02a01d5d-5111-481f-aade-e999a584d8a4",
  "352ba952-a177-4a65-b35c-184f080181cf",
  "29d2a14f-accc-43b8-9444-fd6b9e7902bc",
  "e7ddd974-711f-4fea-90cd-3a89600a72b8",
  "458d74e3-6349-4d58-918b-3d8b4bdf7a6c",
  "e4f8c1ef-2160-47f7-850f-6446ca0680b4",
  "c7d37949-9b15-48a7-a9f3-19f04fe20752",
  "5cddb7c6-3a78-4ae8-9472-28d31c61b803",
  "d8d0e98b-e201-4cd4-a392-48a3142e4bfc",
  "a0be885d-24ad-487d-bbb0-c94cd02a137d",
  "04cd8a98-2f21-4fe2-805f-bd663ca2cc5e",
  "dc440a55-1148-480f-90a7-9d1e0269b682",
  "1f4c5976-8cf3-47e7-be10-aa9270461477",
  "d9041619-7d90-42ea-9811-2b2fe11cb2b0",
  "6323e95e-408a-4598-b6d2-cc44aa64c6f0",
  "1e375923-e5ee-491e-ba21-621a95ef9de9",
  "54f7f313-1a14-4075-b52a-8513811541a6"
]

Code

const axios = require('axios');
const QueryString = require('qs');
const server = require('./server');
const hosts = require('hosts-group');
const dns = require('dns')

console.log('正在查询机房信息...')

Promise.all(server.map(s => {
  return axios({
    url: 'http://ping.chinaz.com/iframe.ashx',
    params: {
      t: 'ping'
    },
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: QueryString.stringify({
      guid: s,
      host: 'github.com',
      ishost: '0',
      isipv6: '0',
      encode: 'vLtCvLxV07f5qlRYHoLFBPaKNX8OZFnP',
      checktype: '0'
    })
  })
})).then(res => {
  const finalTime = res.map(v => v.data).reduce((acc, val) => {
    const data = eval(val)
    if (!data.state) return acc
    const time = data.result.responsetime
    const stime = Number(time.substring(0, time.length - 2))
    if (isNaN(stime)) return acc
    if (acc && acc.result && acc.result.responsetime) {
      const accdata = eval(acc)
      const acctime = accdata.result.responsetime
      const accstime = Number(acctime.substring(0, acctime.length - 2))
      if (stime >= accstime) {
        return accdata
      }
    } else {
      return data
    }
  })

  if (finalTime) {
    console.log('查询机房成功, 延迟最低的机房为: ', finalTime);
  } else {
    console.error('查询机房信息失败,可能是网络波动引起的,建议重试...')
    process.stdout.write("任意字符结束进程")
    process.stdin.on('data', () => {
      process.exit(0);
    })
    return
  }
  console.log('正在设置DNS...')
  dns.lookup('github.com', (err, result) => {
    hosts.remove('github.com', result)
    hosts.set('github.com', finalTime.result.ip)
    console.log('成功! 打开github.com进行检验')
    process.stdout.write("任意字符结束进程") 
    process.stdin.on('data', () => {
      process.exit(0);
    })
  })
}).catch(e => {
  console.error('查询失败, 信息为: ', e)
})

The following libraries are used:

  • axios
  • hosts-group
  • qs

use

In the administrator's command line, run this js file

Github started to take off, Wuhu


陈东民
2.1k 声望269 粉丝

坚持自我 纯粹的技术