栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【python】自动更换本地HOSTS中github.com的ip指向为最低延迟ip

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【python】自动更换本地HOSTS中github.com的ip指向为最低延迟ip

也不知道是从什么时候开始,国内网络访问github动不动就抽风,几分钟快几分钟断,实在受不了了,网上找到了一个chrome插件,但是那ip更新频率也太低了,经常用不了
所以就自己用python写了个自动找最快ip并且自动修改本地hosts的程序

https://github.com/Dark-Athena/auto-github-hosts-py

#!/usr/bin/env python
#coding=utf-8
#功能 :自动设置github.com的host ip
#日期 :2021-09-25 
#作者:Dark-Athena
#email :darkathena@qq.com
#说明:自动从备选ip清单中寻找最低延时IP,设置到本地host中,需要使用管理员权限运行
"""
Copyright DarkAthena
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR ConDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
import ping3

iplist=list((
"13.250.177.223",
"52.69.186.44",
"140.82.112.4",
"52.74.223.119",
"15.164.81.167",
"140.82.113.3",
"13.229.188.59",
"140.82.112.3",
"140.82.114.3",
"20.205.243.166",
"52.192.72.89",
"140.82.121.3",
"140.82.113.4",
"52.78.231.108",
"13.114.40.48",
"140.82.114.4",
"140.82.121.4"
))
PingTime=0.0
MinTime=999.0
for k in iplist:
    PingTime=ping3.ping(k,timeout=1,unit='ms')
    if not PingTime:
        PingTime=5000.0
    if PingTime 

这些备选ip是从站长之家查出来的所有能通的海外ip,之后会尝试修改成自动更新这个ip列表

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/291534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号