Upload 3 files
Browse files- Dockerfile +38 -0
- app.py +117 -0
- torrc +2 -0
Dockerfile
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM debian:bullseye-slim
|
2 |
+
|
3 |
+
# Install dependencies
|
4 |
+
RUN apt-get update && apt-get install -y \
|
5 |
+
tor \
|
6 |
+
python3 \
|
7 |
+
python3-pip \
|
8 |
+
&& rm -rf /var/lib/apt/lists/*
|
9 |
+
|
10 |
+
# Install Python dependencies
|
11 |
+
RUN pip3 install requests requests[socks] fastapi uvicorn
|
12 |
+
|
13 |
+
# Create a non-root user for running Tor
|
14 |
+
RUN useradd -m -s /bin/bash toruser
|
15 |
+
|
16 |
+
# Create Tor data directory and set permissions
|
17 |
+
RUN mkdir -p /var/lib/tor && chown toruser:toruser /var/lib/tor
|
18 |
+
|
19 |
+
# Copy custom torrc configuration
|
20 |
+
COPY torrc /etc/tor/torrc
|
21 |
+
|
22 |
+
# Set working directory
|
23 |
+
WORKDIR /app
|
24 |
+
|
25 |
+
# Copy the application script
|
26 |
+
COPY app.py /app/app.py
|
27 |
+
|
28 |
+
# Make the script executable
|
29 |
+
RUN chmod +x /app/app.py
|
30 |
+
|
31 |
+
# Switch to non-root user
|
32 |
+
USER toruser
|
33 |
+
|
34 |
+
# Expose port for FastAPI (Hugging Face Spaces uses 7860)
|
35 |
+
EXPOSE 7860
|
36 |
+
|
37 |
+
# Run Tor in the background and the FastAPI application
|
38 |
+
CMD tor & uvicorn app:main --host 0.0.0.0 --port 7860
|
app.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
import requests
|
5 |
+
import argparse
|
6 |
+
import sys
|
7 |
+
import asyncio
|
8 |
+
from fastapi import FastAPI
|
9 |
+
from uvicorn import Config, Server
|
10 |
+
|
11 |
+
# Initialize FastAPI app
|
12 |
+
main = FastAPI()
|
13 |
+
|
14 |
+
# FastAPI endpoints
|
15 |
+
@main.get("/")
|
16 |
+
async def root():
|
17 |
+
return {"message": "TOR IS START!"}
|
18 |
+
|
19 |
+
@main.get("/ip")
|
20 |
+
async def get_ip():
|
21 |
+
try:
|
22 |
+
response = requests.get(
|
23 |
+
'http://checkip.amazonaws.com',
|
24 |
+
proxies=dict(http='socks5://127.0.0.1:9050', https='socks5://127.0.0.1:9050')
|
25 |
+
)
|
26 |
+
return {"ip": response.text.strip()}
|
27 |
+
except requests.RequestException as e:
|
28 |
+
return {"error": f"Failed to fetch IP: {str(e)}"}
|
29 |
+
|
30 |
+
def check_and_install_requests():
|
31 |
+
try:
|
32 |
+
import requests
|
33 |
+
except ImportError:
|
34 |
+
print("[+] Python requests is not installed")
|
35 |
+
os.system('pip3 install requests requests[socks]')
|
36 |
+
print("[!] Python requests is installed")
|
37 |
+
|
38 |
+
def get_my_ip():
|
39 |
+
try:
|
40 |
+
response = requests.get(
|
41 |
+
'http://checkip.amazonaws.com',
|
42 |
+
proxies=dict(http='socks5://127.0.0.1:9050', https='socks5://127.0.0.1:9050')
|
43 |
+
)
|
44 |
+
return response.text.strip()
|
45 |
+
except requests.RequestException as e:
|
46 |
+
print(f"[!] Error fetching IP: {e}")
|
47 |
+
return "Unknown"
|
48 |
+
|
49 |
+
def change_ip():
|
50 |
+
try:
|
51 |
+
subprocess.check_output('killall -HUP tor', shell=True)
|
52 |
+
print(f"[+] Your IP has been changed to: {get_my_ip()}")
|
53 |
+
except subprocess.CalledProcessError as e:
|
54 |
+
print(f"[!] Failed to reload Tor: {e}")
|
55 |
+
|
56 |
+
async def ip_change_loop(interval, count):
|
57 |
+
if count == 0:
|
58 |
+
print("Starting infinite IP change. Press Ctrl+C to stop.")
|
59 |
+
try:
|
60 |
+
while True:
|
61 |
+
await asyncio.sleep(interval)
|
62 |
+
change_ip()
|
63 |
+
except KeyboardInterrupt:
|
64 |
+
print('\nAuto IP changer is closed.')
|
65 |
+
sys.exit(0)
|
66 |
+
else:
|
67 |
+
for _ in range(count):
|
68 |
+
await asyncio.sleep(interval)
|
69 |
+
change_ip()
|
70 |
+
|
71 |
+
async def run_app():
|
72 |
+
# Parse command-line arguments
|
73 |
+
parser = argparse.ArgumentParser(description="Tor IP Changer with FastAPI")
|
74 |
+
parser.add_argument('--interval', type=int, default=int(os.getenv('IP_CHANGE_INTERVAL', 60)),
|
75 |
+
help='Time to change IP in seconds (default: 60)')
|
76 |
+
parser.add_argument('--count', type=int, default=int(os.getenv('IP_CHANGE_COUNT', 0)),
|
77 |
+
help='Number of times to change IP (0 for infinite, default: 0)')
|
78 |
+
args = parser.parse_args()
|
79 |
+
|
80 |
+
# Clear terminal
|
81 |
+
os.system("clear")
|
82 |
+
|
83 |
+
# Check and install dependencies
|
84 |
+
check_and_install_requests()
|
85 |
+
|
86 |
+
# Display banner
|
87 |
+
print('''\033[1;32;40m
|
88 |
+
_ _______
|
89 |
+
/\ | | |__ __|
|
90 |
+
/ \ _ _| |_ ___ | | ___ _ __
|
91 |
+
/ /\ \| | | | __/ _ \ | |/ _ \| '__|
|
92 |
+
/ ____ \ |_| | || (_) | | | (_) | |
|
93 |
+
/_/ \_\__,_|\__\___/ |_|\___/|_|
|
94 |
+
V 2.1
|
95 |
+
from mrFD
|
96 |
+
''')
|
97 |
+
print("\033[1;40;31m http://facebook.com/ninja.hackerz.kurdish/\n")
|
98 |
+
print("\033[1;32;40m Using SOCKS proxy at 127.0.0.1:9050\n")
|
99 |
+
print("\033[1;32;40m FastAPI running at http://0.0.0.0:7860\n")
|
100 |
+
|
101 |
+
# Validate inputs
|
102 |
+
interval = args.interval
|
103 |
+
count = args.count
|
104 |
+
if interval <= 0:
|
105 |
+
print("Invalid interval. Using default of 60 seconds.")
|
106 |
+
interval = 60
|
107 |
+
|
108 |
+
# Start the IP change loop in the background
|
109 |
+
asyncio.create_task(ip_change_loop(interval, count))
|
110 |
+
|
111 |
+
if __name__ == "__main__":
|
112 |
+
# Run FastAPI server and IP changer concurrently
|
113 |
+
loop = asyncio.get_event_loop()
|
114 |
+
config = Config(app=main, host="0.0.0.0", port=7860)
|
115 |
+
server = Server(config)
|
116 |
+
loop.run_until_complete(run_app())
|
117 |
+
loop.run_until_complete(server.serve())
|
torrc
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
DataDirectory /var/lib/tor
|
2 |
+
SocksPort 127.0.0.1:9050
|