import requests
from bs4 import BeautifulSoup
from os import system
from time import sleep
import datetime
import threading
from threading import Lock
def get_1(lock):
today = datetime.date.today()
response=requests.get("https://github.com.ipaddress.com/")
soup = BeautifulSoup(response.text, "lxml")
# print(soup.prettify())
r=(soup.find_all('table',class_="panel-item table table-stripes table-v"))[0]
ul=(r.find_all('ul',class_="comma-separated"))[0]
li=(ul.find_all('li'))[0]
print(li.string)
text=li.string+" github.com"
lock.acquire()
with open(r'C:\Windows\System32\drivers\etc\hosts', 'r') as f:
x = f.read()
with open('C:\Windows\System32\drivers\etc\hosts_bk'+str(today), 'w+') as f:
f.write(x)
sleep(1)
with open(r'C:\Windows\System32\drivers\etc\hosts', 'w+') as f:
f.write(text)
lock.release()
def get_2(lock):
response=requests.get("https://fastly.net.ipaddress.com/github.global.ssl.fastly.net")
soup = BeautifulSoup(response.text, "lxml")
# print(soup.prettify())
r = (soup.find_all('table', class_="panel-item table table-stripes table-v"))[0]
ul = (r.find_all('ul', class_="comma-separated"))[0]
li = (ul.find_all('li'))[0]
print(li.string)
lock.acquire()
text=li.string+" github.global.ssl.fastly.net"
with open(r'C:\Windows\System32\drivers\etc\hosts', 'a+') as f:
f.write('\r\n'+text)
lock.release()
def get_3(lock):
response=requests.get("https://github.com.ipaddress.com/assets-cdn.github.com")
soup = BeautifulSoup(response.text, "lxml")
r = (soup.find_all('table', class_="panel-item table table-border-row table-v faq"))[0]
# print(r.prettify())
a = r.find_all('a')
# print(a)
lock.acquire()
for i in a:
print(i.string+" github.github.io")
text=i.string+" github.github.io"
with open(r'C:\Windows\System32\drivers\etc\hosts', 'a+') as f:
f.write('\r\n' + text)
lock.release()
if __name__ == '__main__':
lock1=Lock()
t1=threading.Thread(target=get_1,args=(lock1,))
t2=threading.Thread(target=get_2,args=(lock1,))
t3=threading.Thread(target=get_3,args=(lock1,))
l=[t1,t2,t3]
for t in l:
t.start()
for t in l:
t.join()
sleep(1)
system("ipconfig /flushdns")
sleep(3.5)
制作成exe每天以管理员运行即可
网友评论