Xilixmeaty40 commited on
Commit
75f1785
·
verified ·
1 Parent(s): 05f322e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ from fastapi import FastAPI, BackgroundTasks, HTTPException, Form
4
+ from fastapi.responses import PlainTextResponse, HTMLResponse
5
+ from fastapi.staticfiles import StaticFiles
6
+ from pydantic import BaseModel
7
+ import re
8
+ from concurrent.futures import ThreadPoolExecutor
9
+ import urllib.parse
10
+ import gradio as gr
11
+ import fake_useragent as fake
12
+ import random
13
+ from dotenv import load_dotenv
14
+ import os
15
+ from tqdm import tqdm
16
+ from faker import Faker
17
+ import faker as fakexd
18
+
19
+ load_dotenv()
20
+
21
+ app = FastAPI()
22
+
23
+ class Proxy(BaseModel):
24
+ ip: str
25
+ port: str
26
+
27
+ class VisitRequest(BaseModel):
28
+ url: str
29
+ platform: str
30
+ count: int
31
+ delay: int
32
+ parallel_processes: int
33
+
34
+ app.mount("/static", StaticFiles(directory="static"), name="static")
35
+
36
+ def get_random_proxy():
37
+ pubproxy_url = "http://pubproxy.com/api/proxy?limit=1"
38
+ response = requests.get(pubproxy_url, verify=False)
39
+ data = response.json()
40
+ if data['data']:
41
+ proxy_data = data['data'][0]
42
+ return f"{proxy_data['ip']}:{proxy_data['port']}"
43
+ return None
44
+
45
+ @app.get("/get_proxies", response_class=PlainTextResponse)
46
+ def get_proxies():
47
+ try:
48
+ proxies = []
49
+ pubproxy_url = "http://pubproxy.com/api/proxy?limit=5"
50
+ response = requests.get(pubproxy_url, verify=False)
51
+ data = response.json()
52
+
53
+ for proxy_data in data['data']:
54
+ ip, port = proxy_data['ipPort'].split(":")
55
+ proxy = f"{ip}:{port}"
56
+ proxies.append(proxy)
57
+
58
+ return "\n".join(proxies)
59
+ except Exception as e:
60
+ return PlainTextResponse(str(e), status_code=500)
61
+
62
+ @app.get("/", response_class=PlainTextResponse)
63
+ def rotate_ip():
64
+ try:
65
+ fake = Faker()
66
+ random_ip = fake.ipv4()
67
+
68
+ headers = {
69
+ "X-Forwarded-For": random_ip,
70
+ "Client-IP": random_ip,
71
+ "X-Real-IP": random_ip
72
+ }
73
+
74
+ test_url = "http://pubproxy.com/api/proxy?limit=5"
75
+ response = requests.get(test_url, headers=headers, verify=False)
76
+ data = response.json()
77
+
78
+ proxies = []
79
+ for proxy_data in data['data']:
80
+ ip, port = proxy_data['ipPort'].split(":")
81
+ proxy = f"{ip}:{port}"
82
+ proxies.append(proxy)
83
+
84
+ return "\n".join(proxies)
85
+ except Exception as e:
86
+ return PlainTextResponse(str(e), status_code=500)
87
+
88
+
89
+ if __name__ == "__main__":
90
+ import uvicorn
91
+ uvicorn.run(app, host="0.0.0.0", port=7860)