File size: 3,728 Bytes
fc9e32d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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())