用python来获取Github IP地址
生活随笔
收集整理的這篇文章主要介紹了
用python来获取Github IP地址
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
'''
Title: 快速獲Github網(wǎng)站的IP地址
Author: JackieZheng
Date: 2022-01-20 19:37:35
LastEditTime: 2022-01-22 09:14:49
LastEditors: Please set LastEditors
Description:
FilePath: \\vsTemp\\gitdns.py
'''
import os
import sys
import re
import shutil
import requestshosts_datas=[]
git_ip = []def getip(website:str):"""# 獲取IP地址"""request = requests.get('https://ipaddress.com/website/'+website)if request.status_code == 200:ips=re.findall(r"<strong>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}?)</strong>",request.text)for ip_item in ips:git_ip.append(ip_item+' '+website)getip('github.com')
getip('assets-cdn.github.com')
getip('github.global.ssl.fastly.net')hosts_dir=r'C:\Windows\System32\drivers\etc'
orign_hosts=os.path.join(hosts_dir,'hosts')
temp_hosts=os.path.join(sys.path[0],'hosts')# 讀取原來hosts內(nèi)容
with open(orign_hosts,'r',encoding='utf-8') as orign_file:datas = orign_file.readlines()# 復(fù)制hosts內(nèi)容
hosts_datas=datas.copy()# 刪除原來github相關(guān)內(nèi)容
for data in datas:if 'github' in data or data=='\n':hosts_datas.remove(data)# 合并生成新hosts內(nèi)容
hosts_datas.extend(git_ip)# 生成臨時(shí)hosts文件
with open(temp_hosts,'w') as temp_file:for host in hosts_datas:temp_file.writelines(host+'\n')# 打開系統(tǒng)hosts目錄
os.system("explorer.exe %s" % hosts_dir)try:# 備份 覆蓋 系統(tǒng)hosts文件shutil.move(orign_hosts,orign_hosts+'.bak')shutil.copy(temp_hosts,orign_hosts)INFOR_0="hosts文件已更新成功"print(INFOR_0)
except:INFOR_1="已經(jīng)生成新hosts文件:"+temp_hostsINFOR_2="請手工復(fù)制覆蓋原系統(tǒng)hosts文件"print(INFOR_1,INFOR_2,sep = '\n')INFOR_3="修改完后繼續(xù) 執(zhí)行 清理DNS緩存(ipconfig/flushdns) "
print(INFOR_3)os.system('pause')# 刷新dns緩存
os.system('ipconfig/flushdns')os.system('pause')
https://github.com/JackieZheng/Github-HOSTShttps://github.com/JackieZheng/Github-HOSTS
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的用python来获取Github IP地址的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]使用npm发布vue组件
- 下一篇: 利用Python随机或暴力生成密码