Browse Source

auto build

liuyuqi-dellpc 3 years ago
parent
commit
79e7f18ac0
6 changed files with 99 additions and 63 deletions
  1. 48 0
      .github/workflows/main.yml
  2. 2 0
      .gitignore
  3. 32 31
      hosts
  4. 0 0
      requirements.txt
  5. 14 12
      tools/get_ip_utils.py
  6. 3 20
      tools/main.py

+ 48 - 0
.github/workflows/main.yml

@@ -0,0 +1,48 @@
+name: auto CI
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+  schedule:
+  - cron: "0 2 * * 1-5"
+
+jobs:
+  build:
+
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v2
+        
+      - name: Set up Python 3.8
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.8
+
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+
+      - uses: actions/cache@v1
+        if: startsWith(runner.os, 'Linux')
+        with:
+          path: ~/.cache/pip
+          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+
+      - name: Update Deny Host
+        run: |
+          pwd
+          python tools/main.py
+
+      - name: Push to built branch
+        uses: Automattic/action-commit-to-branch@master
+        with:
+          branch: 'master'
+          commit_message: 'Update Host'
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+/tools/__pycache__/*.pyc
+/.vscode

+ 32 - 31
hosts

@@ -1,31 +1,32 @@
-#*********************github 2020-04-27 update********************
-
-199.232.69.194	github.global.ssl.fastly.net
-185.199.111.153	assets-cdn.github.com
-185.199.109.153	documentcloud.github.com
-199.232.68.133	gist.githubusercontent.com
-185.199.109.154	help.github.com
-140.82.113.9	nodeload.github.com
-199.232.68.133	raw.github.com
-54.85.97.34	status.github.com
-140.82.112.18	training.github.com
-151.101.228.133	avatars0.githubusercontent.com
-151.101.228.133	avatars1.githubusercontent.com
-151.101.108.133	avatars2.githubusercontent.com
-151.101.108.133	avatars3.githubusercontent.com
-151.101.108.133	avatars4.githubusercontent.com
-151.101.108.133	avatars5.githubusercontent.com
-151.101.108.133	avatars6.githubusercontent.com
-151.101.228.133	avatars7.githubusercontent.com
-199.232.68.133	avatars8.githubusercontent.com
-140.82.114.9	codeload.github.com
-199.232.68.133	camo.githubusercontent.com
-199.232.68.133	raw.githubusercontent.com
-199.232.68.133	cloud.githubusercontent.com
-199.232.68.133	user-images.githubusercontent.com
-185.199.111.153	pages.github.com
-140.82.114.6	api.github.com
-140.82.112.26	live.github.com
-140.82.113.4	github.com
-185.199.111.153        customer-stories-feed.github.com
-185.199.111.154        github.githubassets.com
+
+#*********************github 2020-06-08 update********************

+74.86.12.172	github.global.ssl.fastly.net
+185.199.111.153	assets-cdn.github.com
+185.199.110.153	documentcloud.github.com
+8.7.198.45	gist.github.com
+151.101.108.133	gist.githubusercontent.com
+185.199.109.154	github.githubassets.com
+185.199.111.154	help.github.com
+54.251.140.56	nodeload.github.com
+151.101.108.133	raw.github.com
+52.205.36.92	status.github.com
+140.82.114.17	training.github.com
+151.101.108.133	avatars0.githubusercontent.com
+151.101.108.133	avatars1.githubusercontent.com
+151.101.108.133	avatars2.githubusercontent.com
+151.101.108.133	avatars3.githubusercontent.com
+151.101.228.133	avatars4.githubusercontent.com
+151.101.108.133	avatars5.githubusercontent.com
+151.101.108.133	avatars6.githubusercontent.com
+151.101.108.133	avatars7.githubusercontent.com
+151.101.108.133	avatars8.githubusercontent.com
+13.250.162.133	codeload.github.com
+151.101.228.133	camo.githubusercontent.com
+151.101.228.133	raw.githubusercontent.com
+151.101.228.133	cloud.githubusercontent.com
+151.101.228.133	user-images.githubusercontent.com
+185.199.108.153	customer-stories-feed.github.com
+185.199.109.153	pages.github.com
+13.250.94.254	api.github.com
+140.82.113.26	live.github.com
+52.74.223.119	github.com

+ 0 - 0
tools/requirements.txt → requirements.txt


+ 14 - 12
tools/get_ip_utils.py

@@ -2,30 +2,32 @@ import requests
 from bs4 import BeautifulSoup
 import re
 
+
 def getIpFromIpaddress(site):
     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': 'ipaddress.com' }
+               'Host': 'ipaddress.com'}
     url = "https://ipaddress.com/search/" + site
     trueip = None
     try:
-        res = requests.get(url,headers=headers,timeout=2)
+        res = requests.get(url, headers=headers, timeout=2)
         soup = BeautifulSoup(res.text, 'html.parser')
-            ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", c.text)
+        ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", res.text)
         result = soup.find_all('div', class_="comma-separated")
         for c in result:
             if len(ip) != 0:
                 trueip = ip[0]
     except Exception as e:
-        print("查询" + site + " 时出现错误: "+str(e))
+        print("查询" + site + " 时出现错误: " + str(e))
     return trueip
 
+
 def getIpFromChinaz(site):
     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': 'ip.tool.chinaz.com' }
+               'Host': 'ip.tool.chinaz.com'}
     url = "http://ip.tool.chinaz.com/" + site
     trueip = None
     try:
-        res = requests.get(url,headers=headers)
+        res = requests.get(url, headers=headers)
         soup = BeautifulSoup(res.text, 'html.parser')
         result = soup.find_all('span', class_="Whwtdhalf w15-0")
         for c in result:
@@ -33,21 +35,21 @@ def getIpFromChinaz(site):
             if len(ip) != 0:
                 trueip = ip[0]
     except Exception as e:
-        print("查询" + site + " 时出现错误: "+str(e))
+        print("查询" + site + " 时出现错误: " + str(e))
     return trueip
 
 
 def getIpFromWhatismyipaddress(site):
     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': 'ip.tool.chinaz.com' }
+               'Host': 'ip.tool.chinaz.com'}
     url = "https://whatismyipaddress.com//hostname-ip"
-    data={
-        "DOMAINNAME":site,
+    data = {
+        "DOMAINNAME": site,
         "Lookup IP Address": "Lookup IP Address"
     }
     trueip = None
     try:
-        res = requests.post(url,headers=headers,data=data)
+        res = requests.post(url, headers=headers, data=data)
         soup = BeautifulSoup(res.text, 'html.parser')
         result = soup.find_all('span', class_="Whwtdhalf w15-0")
         for c in result:
@@ -55,5 +57,5 @@ def getIpFromWhatismyipaddress(site):
             if len(ip) != 0:
                 trueip = ip[0]
     except Exception as e:
-        print("查询" + site + " 时出现错误: "+str(e))
+        print("查询" + site + " 时出现错误: " + str(e))
     return trueip

+ 3 - 20
tools/main.py

@@ -51,8 +51,7 @@ sites = [
 ]
 
 addr2ip = {}
-# hostLocation = r"C:\Windows\System32\drivers\etc\hosts"
-hostLocation = r"E:\downloads\chrome\speed-github-master\hosts"
+hostLocation = r"hosts"
 
 def dropDuplication(line):
     flag = False
@@ -73,7 +72,6 @@ def updateHost():
         if trueip != None:
             addr2ip[site] = trueip
             print(site + "\t" + trueip)
-    shutil.copy(hostLocation, hostLocation + ".bak")  # 做一份host备份
     with open(hostLocation, "r") as f1:
         f1_lines = f1.readlines()
         with open("temphost", "w") as f2:
@@ -85,22 +83,7 @@ def updateHost():
             for key in addr2ip:
                 f2.write(addr2ip[key] + "\t" + key + "\n")
 
-    shutil.copy("./temphost", hostLocation)
-    os.system("ipconfig /flushdns")
-
-def is_admin():
-    try:
-        return ctypes.windll.shell32.IsUserAnAdmin()
-    except Exception as e:
-        return False
+    os.remove("./temphost")
 
 if __name__ == "__main__":
-    os=platform.system()
-    if os=="Windows":
-        # if is_admin():
-        #     print("admin.....")
-        # else:
-        #     if sys.version_info[0]==3:
-        #         ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
-        #         print("hahhah....")
-        updateHost()
+        updateHost()