forked from jvxiao/speed-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
import re | ||
import shutil | ||
import os | ||
import datetime | ||
|
||
# 需要获取ip的网址 | ||
|
||
sites =[ | ||
"github.com", | ||
"github.global.ssl.fastly.net", | ||
"assets-cdn.github.com", | ||
"documentcloud.github.com", | ||
"gist.github.com", | ||
"help.github.com", | ||
"nodeload.github.com", | ||
"raw.github.com", | ||
"status.github.com", | ||
"training.github.com", | ||
"ithubusercontent.com", | ||
"avatars1.githubusercontent.com", | ||
"codeload.github.com" | ||
] | ||
|
||
addr2ip = {} | ||
|
||
#获取网址的ip | ||
|
||
def getIp(siteAdd): | ||
|
||
engine = "https://ipaddress.com/search/" | ||
headers = headers={'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebkit/737.36(KHTML, like Gecke) Chrome/52.0.2743.82 Safari/537.36','Host':'movie.douban.com' | ||
} | ||
|
||
url = "http://ip.tool.chinaz.com/"+siteAdd | ||
try: | ||
res = requests.get(url) | ||
soup=BeautifulSoup(res.text,'html.parser') | ||
result=soup.find_all('span', class_="Whwtdhalf w15-0") | ||
trueip = None | ||
for c in result: | ||
ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", c.text) | ||
if len(ip)!= 0: | ||
trueip = ip[0] | ||
except: | ||
print("查询"+siteAdd+" 时出现错误") | ||
return None | ||
|
||
return trueip | ||
|
||
|
||
# 生成数据表 | ||
def generateDict(): | ||
|
||
for site in sites: | ||
ip = getIp(site) | ||
if ip != None: | ||
addr2ip[site] = ip | ||
print(site+"\t"+ip) | ||
|
||
|
||
def chachong(line): | ||
flag = False | ||
for site in sites: | ||
if site in line: | ||
flag = flag or True | ||
else: | ||
flag = flag or False | ||
return flag | ||
|
||
|
||
# 更新host, 并刷新本地DNS | ||
|
||
def updateHost(): | ||
generateDict() | ||
today = datetime.date.today() | ||
hostLocation = "C:\Windows\System32\drivers\etc\hosts" | ||
shutil.copy("C:\Windows\System32\drivers\etc\hosts", "C:\Windows\System32\drivers\etc\hosts.bak") # 做一份host备份 | ||
f1 = open("C:\Windows\System32\drivers\etc\hosts", "r") | ||
lines = f1.readlines() | ||
f2 = open("temphost", "w") | ||
|
||
for line in lines: # 为了防止host越写用越长,需要删除之前更新的含有github相关内容 | ||
if chachong(line) == False: | ||
f2.write(line) | ||
f2.write("\n\n #*********************github "+str(today) +" 更新********************\n") | ||
for key in addr2ip: | ||
f2.write(addr2ip[key]+"\t"+key+"\n") | ||
f1.close() | ||
f2.close() | ||
|
||
shutil.copy("./temphost", "C:\Windows\System32\drivers\etc\hosts") #覆盖原来的host | ||
os.system("ipconfig /flushdns") | ||
|
||
updateHost() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 1993-2009 Microsoft Corp. | ||
# | ||
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. | ||
# | ||
# This file contains the mappings of IP addresses to host names. Each | ||
# entry should be kept on an individual line. The IP address should | ||
# be placed in the first column followed by the corresponding host name. | ||
# The IP address and the host name should be separated by at least one | ||
# space. | ||
|
||
74.86.17.48 www.xvideos.com | ||
# Additionally, comments (such as these) may be inserted on individual | ||
# lines or following the machine name denoted by a '#' symbol. | ||
# | ||
# For example: | ||
# | ||
# 102.54.94.97 rhino.acme.com # source server | ||
# 38.25.63.10 x.acme.com # x client host | ||
|
||
# localhost name resolution is handled within DNS itself. | ||
# 127.0.0.1 localhost | ||
# ::1 localhost | ||
|
||
192.168.182.135 xjw.test.com | ||
0.0.0.0 https://account.jetbrains.com:443 | ||
|
||
52.84.246.90 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.252 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.144 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.72 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.106 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.135 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.114 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.90 d3c33hcgiwev3.cloudfront.net | ||
52.84.246.227 d3c33hcgiwev3.cloudfront.net | ||
|
||
|
||
|
||
0.0.0.0 account.jetbrains.com | ||
0.0.0.0 www.jetbrains.com | ||
|
||
|
||
# Github | ||
219.76.4.4 github-cloud.s3.amazonaws.com | ||
|
||
|
||
#*********************github******************** | ||
|
||
|
||
#*********************github 2020-03-21 ����******************** | ||
52.74.223.119 github.com | ||
199.59.149.244 github.global.ssl.fastly.net | ||
185.199.111.153 assets-cdn.github.com | ||
185.199.109.153 documentcloud.github.com | ||
8.7.198.45 gist.github.com | ||
185.199.108.154 help.github.com | ||
13.229.189.0 nodeload.github.com | ||
151.101.228.133 raw.github.com | ||
54.85.97.34 status.github.com | ||
140.82.114.18 training.github.com | ||
37.48.65.151 ithubusercontent.com | ||
151.101.228.133 avatars1.githubusercontent.com | ||
13.250.162.133 codeload.github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo | ||
|
||
set var=D:\worksapce\localgit\speed-github | ||
|
||
python %var%/src/speed.py | ||
@pause |