import sys from bs4 import BeautifulSoup from urllib.request import urlopen
def IP_get(IP): url = "https://ipchaxun.com/"+ IP +"/" Cookies = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-CN,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6", "Connection": "keep-alive", "Cookie": "PHPSESSID=t9dsgluabl4hs1vnneog2fi91d; Hm_lvt_22d5503e9164951ac850495fe15447a7=1588438128; Hm_lpvt_22d5503e9164951ac850495fe15447a7=1588438769", "Host": "ipchaxun.com", "Referer": url, "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1" } res = requests.get(url, headers=Cookies, timeout=30) res.encoding = "utf-8" soup = BeautifulSoup(res.text, "html.parser") Location = soup.find_all("label")[-2].get_text().split(":")[-1].replace("\n","") Suplyer = soup.find_all("label")[-1].get_text().split(":")[-1].replace("\n","") return IP, Location, Suplyer
IPlist = open("TB_IP",'r').read().split("\n")[:-1]
Result = [] for i in IPlist: A,B,C = IP_get(i) print("\t".join([A,B,C])) Result += ["\t".join([A,B,C])]
F = open("IP_location","w") F.write("\n".join(Result)) F.close()
|