新版py3封装pyhttp,ja3指纹
By
money
at 2021-09-15 • 0人收藏 • 871人看过
import py3; import web.json; class pyhttp{ ctor(cookies, agent, proxy){ this.ses = requests.Session(); this.proxies = proxy||{} this.headers={} this.addHeaders = { ["Accept"] = "*/*;q=0.8"; ["Accept-Language"]="zh-CN,zh;q=0.9"; ["Accept-Encoding"]="gzip, deflate, br"; //["Connection"]="Close"; ["User-Agent"]=agent||"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"; }; this.cookies = {@{_readonly = false}}; this.setCookies=function(cookies){ var tp = type(cookies) if(tp==type.table){ ..table.mixin(this.cookies,cookies) }elseif(tp==type.string){ cookies = ..string.replace(cookies,"[\r\n]","") var tab = ..string.split(cookies,';') for(i=1;#tab;1){ var tmp = ..string.split(..string.trim(tab[i]),'=',2); if(#tmp) this.cookies[tmp[1]]=tmp[2]; } } } this.setCookies(cookies) }; setHeaders=function(headers){ this.headers:={} var tp = type(headers) if(tp==type.table){ for(k,v in headers){ this.headers[headerFirstCharToUper(k)]=v } }elseif(tp==type.string){ var tmp = ..string.splitEx(headers, "<\r\n>|\r|\n"); for(i=1;#tmp;1){ var tmp1 = ..string.split(tmp[i],':',2); if(#tmp1==2){ var name = ..string.trim(tmp1[1]) var val = ..string.trim(tmp1[2]); if(name and val){ this.headers[name]=val } } } } } setHeader=function(name, value){ this.headers:={} this.headers[headerFirstCharToUper(name)]=value; } setCookie=function(name, value){ this.cookies[name]=value; } setReferer=function(Referer){ this.headers:={} this.headers["Referer"]=Referer; } post = function(url, postdata, timeout=30000, autoRedirect=true){ this._beforeSend() if(type(postdata)==type.table and postdata.http_post_type=="json"){ postdata.http_post_type=null this.headers["Content-Type"]="application/json"; postdata = json.dumps.invoke(postdata) } var res = this.ses.post.invoke(verify=false, data=postdata, headers=this.headers, proxies=this.proxies, timeout=timeout/1000, allow_redirects=autoRedirect, url); return this._parseData(res); }; get = function(url, datas, timeout=30000, autoRedirect=true){ this._beforeSend() var res = this.ses.get.invoke(verify=false, headers=this.headers, proxies=this.proxies, timeout=timeout/1000, allow_redirects=autoRedirect, url); return this._parseData(res); } _beforeSend = function(){ this.headers = ..table.mix(this.headers, this.addHeaders) var cookie_str = ""; for(k,v in this.cookies){ cookie_str ++= k++"="++tostring(v)+"; " } if(#cookie_str){ cookie_str = ..string.left(cookie_str,#str-2); this.headers["Cookie"] = cookie_str }else { this.headers["Cookie"] = null; } } _parseData = function(res){ var ret = tostring(res.text); if(type(this.beforeDecrypt)==type.function){ ret = this.beforeDecrypt(ret) } if(type(this.decrypt)==type.function){ ret = this.decrypt(ret) } if(type(this.afterDecrypt)==type.function){ ret = this.afterDecrypt(ret) } if(#ret and (..string.startWith(ret,"{") or ..string.startWith(ret,"["))){ var json = ..web.json.tryParse(ret); if(type(json)==type.table){ ret = json } } this.cookies = ..web.json.tryParse(tostring(requests.utils.dict_from_cookiejar.invoke(res.cookies))) return ret, this.cookies; } ja3 = function(url){ this.adapter := DESAdapter.DESAdapter(); this.ses.mount.invoke(url, this.adapter) } } namespace pyhttp{ DESAdaptercode = /** import requests import random from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.ssl_ import create_urllib3_context ORIGIN_CIPHERS = ('ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:' 'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES') class DESAdapter(HTTPAdapter): def __init__(self, *args, **kwargs): """ A TransportAdapter that re-enables 3DES support in Requests. """ CIPHERS = ORIGIN_CIPHERS.split(':') random.shuffle(CIPHERS) CIPHERS = ':'.join(CIPHERS) self.CIPHERS = CIPHERS + ':!aNULL:!eNULL:!MD5' super().__init__(*args, **kwargs) def init_poolmanager(self, *args, **kwargs): context = create_urllib3_context(ciphers=self.CIPHERS) kwargs['ssl_context'] = context return super(DESAdapter, self).init_poolmanager(*args, **kwargs) def proxy_manager_for(self, *args, **kwargs): context = create_urllib3_context(ciphers=self.CIPHERS) kwargs['ssl_context'] = context return super(DESAdapter, self).proxy_manager_for(*args, **kwargs) **/ ..string.save("/DESAdapter.py", DESAdaptercode );//创建一个创建的模块文件 DESAdapter = ..py3.import("DESAdapter"); requests = ..py3.import("requests"); json = ..py3.import("json"); }
使用方式
import console; import pyhttp; var http = pyhttp(); http.ja3("https://ja3er.com")//吼吼,这句是亮点 console.dump(http.get("https://ja3er.com/json")) console.pause(true);
aardio有很多非常棒的http库,本库主要作用是模拟ja3指纹
1 个回复 | 最后更新于 2021-09-15
登录后方可回帖
专门去搜了下什么是ja3
,谢谢分享