SaveText.Ru

Без имени
  1. import argparse
  2.  
  3.  
  4. from aiohttp import web
  5.  
  6.  
  7. def parse_request_origin(request): # https://tech.tiq.cc/2012/06/differences-between-transparent-anonymous-and-elite-proxy/
  8.     headers = request.headers
  9.     proxies_ips = []
  10.     real_ip = headers.get('X-Real-IP')
  11.     proxy_string = headers.get('X-Forwarded-For')
  12.     if proxy_string:
  13.         proxies_ips = [proxy.strip() for proxy in proxy_string.split(',')]
  14.     return {
  15.         'real_ip': real_ip,
  16.         'proxy_server_name': headers.get('Via'),
  17.         'proxy_ips': proxies_ips
  18.     }
  19.  
  20.  
  21. async def get_request_origin(request):
  22.     return web.json_response(
  23.         parse_request_origin(request)
  24.     )
  25.  
  26. parser = argparse.ArgumentParser(description='aiohttp myip server')
  27. parser.add_argument('--path')
  28. app = web.Application()
  29. app.add_routes([web.get('/myip', get_request_origin)])
  30.  
  31.  
  32. if __name__ == '__main__':
  33.     args = parser.parse_args()
  34.     web.run_app(app, path=args.path)
  35.  

Share with your friends:

Print