import time import os import subprocess import requests import argparse import sys import asyncio from fastapi import FastAPI from uvicorn import Config, Server # Initialize FastAPI app main = FastAPI() # FastAPI endpoints @main.get("/") async def root(): return {"message": "TOR IS START!"} @main.get("/ip") async def get_ip(): try: response = requests.get( 'http://checkip.amazonaws.com', proxies=dict(http='socks5://127.0.0.1:9050', https='socks5://127.0.0.1:9050') ) return {"ip": response.text.strip()} except requests.RequestException as e: return {"error": f"Failed to fetch IP: {str(e)}"} def check_and_install_requests(): try: import requests except ImportError: print("[+] Python requests is not installed") os.system('pip3 install requests requests[socks]') print("[!] Python requests is installed") def get_my_ip(): try: response = requests.get( 'http://checkip.amazonaws.com', proxies=dict(http='socks5://127.0.0.1:9050', https='socks5://127.0.0.1:9050') ) return response.text.strip() except requests.RequestException as e: print(f"[!] Error fetching IP: {e}") return "Unknown" def change_ip(): try: subprocess.check_output('killall -HUP tor', shell=True) print(f"[+] Your IP has been changed to: {get_my_ip()}") except subprocess.CalledProcessError as e: print(f"[!] Failed to reload Tor: {e}") async def ip_change_loop(interval, count): if count == 0: print("Starting infinite IP change. Press Ctrl+C to stop.") try: while True: await asyncio.sleep(interval) change_ip() except KeyboardInterrupt: print('\nAuto IP changer is closed.') sys.exit(0) else: for _ in range(count): await asyncio.sleep(interval) change_ip() async def run_app(): # Parse command-line arguments parser = argparse.ArgumentParser(description="Tor IP Changer with FastAPI") parser.add_argument('--interval', type=int, default=int(os.getenv('IP_CHANGE_INTERVAL', 60)), help='Time to change IP in seconds (default: 60)') parser.add_argument('--count', type=int, default=int(os.getenv('IP_CHANGE_COUNT', 0)), help='Number of times to change IP (0 for infinite, default: 0)') args = parser.parse_args() # Clear terminal os.system("clear") # Check and install dependencies check_and_install_requests() # Display banner print('''\033[1;32;40m _ _______ /\ | | |__ __| / \ _ _| |_ ___ | | ___ _ __ / /\ \| | | | __/ _ \ | |/ _ \| '__| / ____ \ |_| | || (_) | | | (_) | | /_/ \_\__,_|\__\___/ |_|\___/|_| V 2.1 from mrFD ''') print("\033[1;40;31m http://facebook.com/ninja.hackerz.kurdish/\n") print("\033[1;32;40m Using SOCKS proxy at 127.0.0.1:9050\n") print("\033[1;32;40m FastAPI running at http://0.0.0.0:7860\n") # Validate inputs interval = args.interval count = args.count if interval <= 0: print("Invalid interval. Using default of 60 seconds.") interval = 60 # Start the IP change loop in the background asyncio.create_task(ip_change_loop(interval, count)) if __name__ == "__main__": # Run FastAPI server and IP changer concurrently loop = asyncio.get_event_loop() config = Config(app=main, host="0.0.0.0", port=7860) server = Server(config) loop.run_until_complete(run_app()) loop.run_until_complete(server.serve())