import requests from bs4 import BeautifulSoup from fastapi import FastAPI, BackgroundTasks, HTTPException, Form from fastapi.responses import PlainTextResponse, HTMLResponse from fastapi.staticfiles import StaticFiles from pydantic import BaseModel import re from concurrent.futures import ThreadPoolExecutor import urllib.parse import gradio as gr import fake_useragent as fake import random from dotenv import load_dotenv import os from tqdm import tqdm from faker import Faker import faker as fakexd load_dotenv() app = FastAPI() class Proxy(BaseModel): ip: str port: str class VisitRequest(BaseModel): url: str platform: str count: int delay: int parallel_processes: int def get_random_proxy(): pubproxy_url = "http://pubproxy.com/api/proxy" response = requests.get(pubproxy_url, verify=False) data = response.json() if data['data']: proxy_data = data['data'][0] return f"{proxy_data['ip']}:{proxy_data['port']}" return None @app.get("/get_proxies", response_class=PlainTextResponse) def get_proxies(): try: proxies = [] pubproxy_url = "http://pubproxy.com/api/proxy" response = requests.get(pubproxy_url, verify=False) data = response.json() for proxy_data in data['data']: ip, port = proxy_data['ipPort'].split(":") proxy = f"{ip}:{port}" proxies.append(proxy) return "\n".join(proxies) except Exception as e: return PlainTextResponse(str(e), status_code=500) @app.get("/", response_class=PlainTextResponse) def rotate_ip(): try: fake = Faker() random_ip = fake.ipv4() headers = { "X-Forwarded-For": random_ip, "Client-IP": random_ip, "X-Real-IP": random_ip } test_url = "http://pubproxy.com/api/proxy?type=socks4" response = requests.get(test_url, headers=headers, verify=False) data = response.json() proxies = [] for proxy_data in data['data']: ip, port = proxy_data['ipPort'].split(":") proxy = f"{ip}:{port}" proxies.append(proxy) return "\n".join(proxies) except Exception as e: return PlainTextResponse(str(e), status_code=500) if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=7860)