netproxy17 / app.py
Nyx9's picture
test
25226b3 verified
from flask import Flask,request,Response,jsonify
import requests,os,json
a=Flask(__name__)
@a.route('/')
def index(): return 'OK proxy'+str(requests.get("https://ifconfig.me/ip").text)
@a.route('/go',methods=['GET','POST'])
def go():
try:
url=request.args.get('url'); method=request.args.get('m','GET'); hdr={}
if request.args.get('headers'): hdr=json.loads(request.args['headers'])
data=request.data
if request.is_json: data=request.json
r=requests.request(method,url,headers=hdr,data=(json.dumps(data) if isinstance(data,dict) else data),timeout=100)
return Response(r.content,status=r.status_code,headers={'Content-Type':r.headers.get('Content-Type','text/plain'),'x-head':str(dict(r.headers))[:4000]})
except Exception as e:return str(e),500
@a.route('/search')
def search():
try:
from duckduckgo_search import DDGS
return jsonify(list(DDGS().text(request.args.get('q'),max_results=20)))
except Exception as e:return 'ERR'+repr(e)
if __name__=='__main__': a.run(host='0.0.0.0',port=7860)