Skip to content

Commit

Permalink
add source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jvxiao committed Mar 21, 2020
1 parent 4c4cb75 commit f2dff15
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ CDN,Content Distribute Network,可以直译成内容分发网络,CDN解决
将获取的ip与对应的网址填入host文件中,然后刷新本地DNS.


### 运行环境

- python3+
- 依赖库
- BeautifulSoup
- requsts
- shutil

### 使用方式



1. 用记事本或notepad++打开startFly.bat文件,将 var变量值改成你自己存放该项目的地址
2. 右键点击startFly.bat, 以管理员身份运行
Binary file added img/screenShot.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions src/speed.py
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()
63 changes: 63 additions & 0 deletions src/temphost
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
6 changes: 6 additions & 0 deletions startFly.bat
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

0 comments on commit f2dff15

Please sign in to comment.