def cmd5_get_result(self, r_url, r_header, r_data, rps): if "验证码错误" in rps: request_img_url = "https://www.cmd5.com/checkcode.aspx/0?" + self.cmd5_repe * "?" request_img_header = { "Host": "www.cmd5.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "image/webp,*/*", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Referer": "https://www.cmd5.com/", "Connection": "keep-alive", "Pragma": "no-cache", "Cache-Control": "no-cache", "TE": "Trailers" } response_img = host.get(url=request_img_url, headers=request_img_header) open(self.path + '/img/cimg.gif', 'wb').write(response_img.content) # 将内容写入图片 del response_img code_demo = Code(img_path=self.path + "/img/cimg.gif", name="cmd5", code_num=4, search_num=1) code_result = code_demo.get_code() if self.cmd5_repe > 4: return 0, "验证码错误" if code_result["code"] == 0: self.cmd5_repe += 1 return self.cmd5_get_result(r_url, r_header, r_data, rps) else: r_data["ctl00$ContentPlaceHolder1$TextBoxCode"] = code_result[ "result"] response_md5 = host.post(url=r_url, headers=r_header, data=r_data) html_md5 = HTML(response_md5.text) text_md5 = html_md5.xpath( '//*[@id="ctl00_ContentPlaceHolder1_table3"]/tr/td/div/span//text()' ) self.cmd5_repe += 1 return self.cmd5_get_result(r_url, r_header, r_data, text_md5) elif rps[0] == "请": return 0, "需要登录" else: return 1, rps[0]
def get_dumpster(self): req_url = "https://dnsdumpster.com/" get_c_res = requests.get(req_url) cookie_dict = filter_cookie(get_c_res, get_type="dict") cookie_str = filter_cookie(get_c_res) req_data = { "csrfmiddlewaretoken": cookie_dict['csrftoken'], "targetip": self.targetip } req_header = { "Host": "dnsdumpster.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "107", "Origin": "https://dnsdumpster.com", "Connection": "keep-alive", "Referer": "https://dnsdumpster.com/", "Cookie": cookie_str, "Upgrade-Insecure-Requests": "1", "Pragma": "no-cache", "Cache-Control": "no-cache", } res = requests.post(req_url, data=req_data, headers=req_header) html = HTML(res.text) d_tr_text = '//*[@id="intro"]/div[1]/div[3]/div/div[4]/table/tr' DNS_Servers = html.xpath(d_tr_text) d_len = len(DNS_Servers) d_resu = get_table(d_len, 1, None, html, d_tr_text) self.result["DNS_Servers"] = d_resu mx_tr_text = '//*[@id="intro"]/div[1]/div[3]/div/div[5]/table/tr' MX_Records = html.xpath(d_tr_text) mx_len = len(MX_Records) mx_resu = get_table(mx_len, 1, None, html, mx_tr_text) self.result["MX_Records"] = mx_resu tx_tr_text = '//*[@id="intro"]/div[1]/div[3]/div/div[6]/table/tr' TXT_Records = html.xpath(d_tr_text) tx_len = len(TXT_Records) tx_resu = get_table(tx_len, 1, None, html, tx_tr_text) self.result["TXT_Records"] = tx_resu hr_tr_text = '//*[@id="intro"]/div[1]/div[3]/div/div[7]/table/tr' Host_Records_A = html.xpath(d_tr_text) hr_len = len(Host_Records_A) hr_resu = get_table(hr_len, 1, None, html, hr_tr_text) self.result["TXT_Records"] = hr_resu return self.result
def md5_tellyou(self): request_url = "http://md5.tellyou.top/default.html" response = host.get(request_url) html = HTML(response.text) VIEWSTATE = html.xpath('//*[@id="__VIEWSTATE"]/@value') VIEWSTATEGENERATOR = html.xpath( '//*[@id="__VIEWSTATEGENERATOR"]/@value') EVENTVALIDATION = html.xpath('//*[@id="__EVENTVALIDATION"]/@value') MD5GET = "正在处理" request_header = { "Host": "md5.tellyou.top", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Referer": "http://md5.tellyou.top/default.html", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "1512", "Origin": "http://md5.tellyou.top", "Connection": "keep-alive", "Upgrade-Insecure-Requests": "1" } request_data = { "__VIEWSTATE": VIEWSTATE, "__VIEWSTATEGENERATOR": VIEWSTATEGENERATOR, "__EVENTVALIDATION": EVENTVALIDATION, "Textmd5": self.Textmd5, "MD5GET": MD5GET } response_md5 = host.post(url=request_url, headers=request_header, data=request_data) html_md5 = HTML(response_md5.text) md5_text = html_md5.xpath('//td[@class="styleh"]/span[2]//text()') return 1, md5_text[0]
def get_ping(self): ini_req_url = "http://ping.chinaz.com/" + self.ip ini_req_header = { "Host": "ping.chinaz.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "129", "Origin": "http://ping.chinaz.com", "Connection": "keep-alive", "Referer": "http://ping.chinaz.com/" + self.ip, "Upgrade-Insecure-Requests": "1", "Pragma": "no-cache", "Cache-Control": "no-cache", } ini_req_data = {"host": self.ip, "linetype": "电信,多线,联通,移动,海外"} ini_res = host.post(url=ini_req_url, data=ini_req_data, headers=ini_req_header) ck = filter_cookie(ini_res) html = HTML(ini_res.text) guid_list = xfilter( html.xpath( "//*[@id='speedlist']/div[contains(@class,'listw')]/@id")) city_num = len(guid_list) encode = xfilter(html.xpath("//*[@id='enkey']/@value")) ishost = xfilter(html.xpath("//*[@id='ishost']/@value")) isipv6 = xfilter(html.xpath("//*[@id='isipv6']/@value")) checktype = xfilter(html.xpath("//*[@id='checktype']/@value")) radom_13 = get_radom("0123456789", 13) request_url = "http://ping.chinaz.com/iframe.ashx?t=ping&callback=jQuery11130" + radom_13 + "_" + str( int(time.time() * 1000)) request_header = { "Host": "ping.chinaz.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Referer": "http://ping.chinaz.com/" + self.ip, "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", "Content-Length": "129", "Origin": "http://ping.chinaz.com", "Connection": "keep-alive", "Cookie": ck, "Pragma": "no-cache", "Cache-Control": "no-cache" } result_data = {"city_num": city_num} cont_num = 0 for guid in guid_list: if guid in self.set: result_data["city_num"] = city_num - 1 city_num -= 1 continue self.set.add(guid) city = xfilter( html.xpath("//*[@id='speedlist']/div[@id='" + guid + "']/div[@name='city']/text()")) if type(city) == list: city = city[0] request_data = { "guid": guid, "host": self.ip, "ishost": ishost, "isipv6": isipv6, "encode": encode, "checktype": checktype } response = host.post(url=request_url, data=request_data, headers=request_header) data_re = re.findall(".*\((.*)\)", response.text) data_0 = data_re[0].replace("'", '"') if data_re else "" data_dict = demjson.decode(data_0) data_json = json.loads(json.dumps(data_dict)) cont_num += 1 print(city_num, cont_num, city, data_json) result_data[str(cont_num)] = { "city": city, "result": data_json["result"] } if data_json['state'] == 1 else "请求超时" print(result_data) return result_data
def get_icp(self): request_url_1 = "http://icp.chinaz.com/" + self.url_icp_companyName_q request_header = { "Host": "icp.chinaz.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://icp.chinaz.com/" + self.url_icp_companyName_q, "Upgrade-Insecure-Requests": "1", "Pragma": "no-cache", "Cache-Control": "no-cache", } response_1 = host.get(url=request_url_1, headers=request_header) html = HTML(response_1.text) get_first_id = xfilter(html.xpath('//*[@id="first"]')) if get_first_id is not None: company_name = xfilter( html.xpath('//*[@id="first"]/li[1]/p/a/text()')) unit_properties = xfilter( html.xpath('//*[@id="first"]/li[2]/p/strong/text()')) icp_id = xfilter( html.xpath('//*[@id="first"]/li[3]/p/font/text()')) web_name = xfilter(html.xpath('//*[@id="first"]/li[4]/p/text()')) web_home_isture = xfilter( html.xpath('//*[@id="first"]/li[5]/span/text()')) if web_home_isture == "网站负责人": web_home_url = xfilter( html.xpath('//*[@id="first"]/li[6]/p/text()')) verify_time = xfilter( html.xpath('//*[@id="first"]/li[8]/p/text()')) else: web_home_url = xfilter( html.xpath('//*[@id="first"]/li[5]/p/text()')) verify_time = xfilter( html.xpath('//*[@id="first"]/li[7]/p/text()')) self.result["icp_data"] = { "company_name": company_name, "unit_properties": unit_properties, "icp_id": icp_id, "web_name": web_name, "web_home_isture": web_home_isture, "web_home_url": web_home_url, "verify_time": verify_time } else: self.result["icp_data"] = None request_header[ "Accept"] = "application/json, text/javascript, */*; q=0.01" request_header["Accept-Encoding"] = "gzip, deflate" request_header[ "Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" request_header["X-Requested-With"] = "XMLHttpRequest" request_header["Content-Length"] = "13" request_header["Origin"] = "http://icp.chinaz.com" request_qiye_url = "http://icp.chinaz.com/Home/QiYeData" request_qiye_data = {"Kw": self.url_icp_companyName} response_qiye = host.post(url=request_qiye_url, data=request_qiye_data, headers=request_header) response_qiye_json = json.loads(response_qiye.text) if response_qiye_json["code"] == 200 and response_qiye_json[ "data"] is not None: self.result["company_data"] = response_qiye_json["data"] #获取企业的Icp备案 request_company_icp_url = "http://icp.chinaz.com/Home/PageData" request_company_icp_data = { "pageNo": "1", "pageSize": "10", "Kw": response_qiye_json["data"]["companyName"] } request_header["Content-Length"] = "150" response_company_icp = host.post(url=request_company_icp_url, data=request_company_icp_data, headers=request_header) response_company_icp_json = json.loads(response_company_icp.text) if response_company_icp_json["code"] == 200: self.result["company_other_icp"] = self.get_page_data( response_company_icp_json["data"], request_company_icp_url, request_company_icp_data, request_header, response_company_icp_json['amount'], response_company_icp_json['pageSize']) else: self.result["company_other_icp"] = response_company_icp_json[ "data"] #获取企业注销的icp company_delicp_result = {} request_company_delicp_url = "http://icp.chinaz.com/Home/PageDelData" request_company_delicp_data = { "pageNo": "1", "pageSize": "10", "Kw": response_qiye_json["data"]["companyName"] } response_company_delicp = host.post( url=request_company_delicp_url, data=request_company_delicp_data, headers=request_header) response_company_delicp_json = json.loads( response_company_delicp.text) if response_company_delicp_json["code"] == 200: self.result["company_delicp"] = self.get_page_data( response_company_delicp_json["data"], request_company_delicp_url, request_company_delicp_data, request_header, response_company_delicp_json['amount'], response_company_delicp_json['pageSize']) else: self.result["company_delicp"] = response_company_delicp_json[ "data"] else: self.result["company_data"] = response_qiye_json["data"] return self.result
def get_whois(self): res_url = "http://whois.chinaz.com/" + self.DomainName res_header = { "Host": "whois.chinaz.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Referer": "http://whois.chinaz.com/" + self.DomainName, "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "59", "Origin": "http://whois.chinaz.com", "Connection": "keep-alive", "Upgrade-Insecure-Requests": "1", "Pragma": "no-cache", "Cache-Control": "no-cache" } res_data = { "DomainName": self.DomainName, "ws": "grs-whois.hichina.com", "isforceupdate": "" } response = host.post(url=res_url, data=res_data, headers=res_header) html = HTML(response.text) Domain_Name_xpath = html.xpath( '//*[@id="sh_info"]/li[1]/div[2]/p[1]/a[1]/text()') #域名 Registrar_xpath = html.xpath( '//*[@id="sh_info"]/li[2]/div[2]/div/span/text()') #注册商 ContactEmail_xpath = html.xpath( '//*[@id="sh_info"]/li[3]/div[2]/span/text()') #联系邮箱 ContactPhone_xpath = html.xpath( '//*[@id="sh_info"]/li[4]/div[2]/span/text()') #联系电话 CreationDate_xpath = html.xpath( '//*[@id="sh_info"]/li[5]/div[2]/span/text()') #创建时间 UpdatedDate_xpath = html.xpath( '//*[@id="sh_info"]/li[5]/div[2]/span/text()') #更新时间 ExpiryDate_xpath = html.xpath( '//*[@id="sh_info"]/li[7]/div[2]/span/text()') #到期时间 RegistrarServer_xpath = html.xpath( '//*[@id="sh_info"]/li[8]/div[2]/span/text()') #域名服务器 DNS = html.xpath('//*[@id="sh_info"]/li[9]/div[2]/text()') #DNS DomainStatus_xpath = html.xpath( '//*[@id="sh_info"]/li[10]/div[2]/p/span/text()') #状态 Domain_Name, Registrar, ContactEmail, ContactPhone = xfilter( Domain_Name_xpath, Registrar_xpath, ContactEmail_xpath, ContactPhone_xpath) CreationDate, UpdatedDate, ExpiryDate = xfilter( CreationDate_xpath, UpdatedDate_xpath, ExpiryDate_xpath) RegistrarServer, DomainStatus = xfilter(RegistrarServer_xpath, DomainStatus_xpath) result = { "域名": Domain_Name, "注册商": Registrar, "联系邮箱": ContactEmail, "联系电话": ContactPhone, "创建时间": CreationDate, "更新时间": UpdatedDate, "到期时间": ExpiryDate, "域名服务器": RegistrarServer, "DNS": DNS, "状态": DomainStatus, } return result
def get_crt(self): REQ_URL = "https://crt.sh/?q="+self.key REQ_HEADER = { "Host": "crt.sh", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Connection": "keep-alive", "Upgrade-Insecure-Requests": "1", "Pragma": "no-cache", "Cache-Control": "no-cache", } res = host.get(REQ_URL,REQ_HEADER) html = HTML(res.text) crt_shID = xfilter(html.xpath("//table[2]/tr[1]/td/a/text()")) Summary = xfilter(html.xpath("//table[2]/tr[2]/td/text()")) self.result["crt_shID"] = crt_shID self.result["Summary"] = Summary if not len(crt_shID) and not len(Summary): print({"value":None}) return ({"value": None}) ct_td_text = "//table[2]/tr[3]/td/div/table/tr/td[1]/table/tr" Certificate_Transparency = html.xpath(ct_td_text) ct_th = html.xpath(ct_td_text+"/th/text()") ct_len = len(Certificate_Transparency)-2 ct_tr_start_num = 3 self.result["Certificate_Transparency"] = get_table(ct_len, ct_tr_start_num, ct_th, html, ct_td_text) rt_td_text = "//table[2]/tr[4]/td/table/tr" Revocation = html.xpath(rt_td_text) rt_th = html.xpath(rt_td_text+"/th/text()") rt_len = len(Revocation)-1 rt_tr_start_num = 2 self.result["Revocation"] = get_table(rt_len,rt_tr_start_num,rt_th,html,rt_td_text) rf_td_text = "//table[2]/tr[5]/td/table/tr" RevoCertificate_Fingerprints= html.xpath(rf_td_text) rf_th = html.xpath(rf_td_text+"/th/text()") rf_len = len(RevoCertificate_Fingerprints) rf_tr_start_num = 1 self.result["RevoCertificate_Fingerprints"] = get_table(rf_len, rf_tr_start_num, rf_th, html, rf_td_text,self.table_gdata) self.result["Certificate "] = html.xpath("//table[2]/tr[6]/td//text()") return self.result
def md5_cmd5(self): request_url = "https://www.cmd5.com/" response = host.get(request_url) html = HTML(response.text) EVENTTARGET_xpath = html.xpath('//*[@id="__EVENTTARGET"]/@value') EVENTTARGET = EVENTTARGET_xpath[0] if EVENTTARGET_xpath else "" EVENTARGUMENT_xpath = html.xpath('//*[@id="__EVENTARGUMENT"]/@value') EVENTARGUMENT = EVENTARGUMENT_xpath[0] if EVENTARGUMENT_xpath else "" VIEWSTATE_xpath = html.xpath('//*[@id="__VIEWSTATE"]/@value') VIEWSTATE = VIEWSTATE_xpath[0] if VIEWSTATE_xpath else "" VIEWSTATEGENERATOR_xpath = html.xpath( '//*[@id="__VIEWSTATEGENERATOR"]/@value') VIEWSTATEGENERATOR = VIEWSTATEGENERATOR_xpath[ 0] if VIEWSTATEGENERATOR_xpath else "" InputHashType = "md5" HiddenField1_xpath = html.xpath( '//*[@id="ctl00_ContentPlaceHolder1_HiddenField1"]/@value') HiddenField1 = HiddenField1_xpath[0] if HiddenField1_xpath else "" HiddenField2_xpath = html.xpath( '//*[@id="ctl00_ContentPlaceHolder1_HiddenField2"]/@value') HiddenField2 = HiddenField2_xpath[0] if HiddenField2_xpath else "" request_data = { "__EVENTTARGET": EVENTTARGET, "__EVENTARGUMENT": EVENTARGUMENT, "__VIEWSTATE": VIEWSTATE, "__VIEWSTATEGENERATOR": VIEWSTATEGENERATOR, "ctl00$ContentPlaceHolder1$TextBoxInput": self.Textmd5, "ctl00$ContentPlaceHolder1$InputHashType": InputHashType, "ctl00$ContentPlaceHolder1$Button1": "查询", "ctl00$ContentPlaceHolder1$HiddenField1": HiddenField1, "ctl00$ContentPlaceHolder1$HiddenField2": HiddenField2 } request_header = { "Host": "www.cmd5.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "2631", "Origin": "https://www.cmd5.com", "Connection": "keep-alive", "Referer": "https://www.cmd5.com/", "Upgrade-Insecure-Requests": "1" } response_md5 = host.post(url=request_url, headers=request_header, data=request_data) html_md5 = HTML(response_md5.text) text_md5 = html_md5.xpath( '//*[@id="ctl00_ContentPlaceHolder1_table3"]/tr/td/div/span//text()' ) result_md5 = self.cmd5_get_result(request_url, request_header, request_data, text_md5) return result_md5