美文网首页iOS 进阶
github访问慢的解决办法(macOS)

github访问慢的解决办法(macOS)

作者: 猎手Andy | 来源:发表于2020-01-05 12:28 被阅读0次

编辑 /etc/hosts

cd /etc
sudo vi hosts

进去以后 输入 字母 i进入编辑模式
输入对应的ip:host
输入完成以后,按Esc,输入:wq

修改域名IP对应关系:参考如下

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
185.199.108.153 documentcloud.github.com
192.30.253.112 github.com
192.30.253.118 gist.github.com
185.199.108.154 help.github.com
140.82.113.9 nodeload.github.com
199.232.28.133 raw.github.com
52.87.114.63 status.github.com
140.82.114.17 training.github.com
140.82.113.3 www.github.com
::1             localhost

查询域名对应IP的方法

https://www.ipaddress.com

写了个脚本:

githubhosts.py

import os 
import sys 
import re

githubhosts = [
    "documentcloud.github.com",
    "github.com",
    "desktop.github.com",
    "github.global.ssl.fastly.net",
    "codeload.github.com",
    "assets-cdn.github.com",
    "github.global.ssl.fastly.net",
    "gist.github.com",
    "help.github.com",
    "nodeload.github.com",
    "raw.github.com",
    "status.github.com",
    "training.github.com",
    "www.github.com"
    ]
resultList = list()
for host in githubhosts:
    cmd = 'ping -c 1 %s' % host
    print(cmd)
    content = os.popen(cmd).read()
    result = content.split("\n")
    firstLine = result[0]
    reg = re.compile('PING\s(.*)\s\((.*)\):\s56\sdata\sbytes')
    regMatch = reg.search(firstLine)
    ip = regMatch.groups()[1]
    print("%s -> %s" % (host,ip))
    resultList.append("%s %s" % (ip,host))
    pass

finalResult = '\n'.join(resultList)
print('=====================================================================================')
print(finalResult)
print('=====================================================================================')
print('Copy the ip-host map and replace in /etc/hosts')
print('Run dscacheutil -flushcache')

相关文章

网友评论

    本文标题:github访问慢的解决办法(macOS)

    本文链接:https://www.haomeiwen.com/subject/fkiqactx.html