Skip to content

Commit e199930

Browse files
authored
Merge pull request #3 from papanya02/Windows-Support
Added Windows support to the script"
2 parents d3b319d + fb01e43 commit e199930

File tree

4 files changed

+320
-121
lines changed

4 files changed

+320
-121
lines changed

IP-Changer.py

Lines changed: 16 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,25 @@
1-
import subprocess
2-
import requests
3-
import time
4-
import sys
51
import os
2+
import sys
3+
from scr import main_win
4+
from scr import main_linux
65

7-
if os.name == 'nt':
8-
sys.exit("This tool can only run on Linux!")
9-
10-
def display_banner():
11-
os.system('cls' if os.name == 'nt' else 'clear')
12-
DEFAULT, GREEN, RED, YELLOW, YELLOW2, ITALIC, BLINK = '\033[0m', '\033[1;92m', '\033[1;31m', '\033[1;33m', '\033[1;93m', '\033[3m', '\033[5m'
13-
14-
print('''
15-
{4} █████ ███████████ █████████ █████ █████ █████████ ██████ █████ █████████ ██████████ ███████████{0}
16-
{4}░░███ ░░███░░░░░███ ███░░░░░███░░███ ░░███ ███░░░░░███ ░░██████ ░░███ ███░░░░░███░░███░░░░░█░░███░░░░░███{0}
17-
{4} ░███ ░███ ░███ ███ ░░░ ░███ ░███ ░███ ░███ ░███░███ ░███ ███ ░░░ ░███ █ ░ ░███ ░███{0}
18-
{4} ░███ ░██████████ ░███ ░███████████ ░███████████ ░███░░███░███ ░███ ░██████ ░██████████{0}
19-
{4} ░███ ░███░░░░░░ ░███ ░███░░░░░███ ░███░░░░░███ ░███ ░░██████ ░███ █████ ░███░░█ ░███░░░░░███{0}
20-
{4} ░███ ░███ ░░███ ███ ░███ ░███ ░███ ░███ ░███ ░░█████ ░░███ ░░███ ░███ ░ █ ░███ ░███{0}
21-
{4} █████ █████ ░░█████████ █████ █████ █████ █████ █████ ░░█████ ░░█████████ ██████████ █████ █████{0}
22-
{4}░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░{0}
23-
24-
{1}{5}================ {1}{5}======================
25-
{3}{5}Version: {2}1.0{2} {3}{5}Code Author: {2}isPique
26-
{1}{5}================ {1}{5}======================
276

28-
{3}{5}GitHub Profile {2}{6}:{0}{1} https://github.com/isPique{0}
29-
'''.format(DEFAULT, GREEN, RED, YELLOW, YELLOW2, ITALIC, BLINK))
7+
def run_windows_script():
8+
print("Running Windows script...")
9+
main_win.main()
3010

31-
def install_tor():
32-
if subprocess.run(['which', 'tor'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).returncode != 0:
33-
print("\033[1;91m[!]\033[1;93m Tor is not installed. Installing it...\033[0m")
34-
if os.system("sudo apt install tor -y > /dev/null 2>&1"):
35-
print("\033[1;91m[!]\033[1;93m Failed to install Tor!\n\033[1;91m[!]\033[1;93m Please check your network connection.\033[0m")
36-
return False
37-
else:
38-
print("\033[1;92m[+] Tor has been successfully installed.\033[0m")
39-
time.sleep(1)
40-
return True
11+
def run_linux_script():
12+
print("Running Linux script...")
13+
main_linux.main()
4114

4215
def main():
43-
# Check if script is running with root privileges
44-
if os.geteuid() != 0:
45-
print("\033[1;91m[!]\033[1;93m This script must be run with root privileges.\033[0m")
46-
return
47-
48-
url = "https://httpbin.org/ip"
49-
proxy = {
50-
'http': 'socks5://127.0.0.1:9050',
51-
'https': 'socks5://127.0.0.1:9050'
52-
}
53-
54-
try:
55-
print("\033[1;34m[*] Checking if Tor is installed...\033[0m")
56-
time.sleep(1)
57-
if not install_tor():
58-
return
59-
else:
60-
print("\033[1;92m[+] Tor is already installed.\033[0m")
61-
time.sleep(1)
62-
63-
display_banner()
64-
65-
try:
66-
version_info = os.popen("tor --version").read().strip()
67-
version = version_info.split('\n')[0].split(' ')[2]
68-
print(f"\033[1;34m[*] Your Tor version is: {version}\033[0m")
69-
except Exception:
70-
pass
71-
72-
try:
73-
response = requests.get(url)
74-
current_ip = response.json()["origin"]
75-
print(f"\033[1;34m[*] Your current IP address is: {current_ip}\033[0m")
76-
except:
77-
pass
78-
79-
try:
80-
time_interval = int(input("\033[1;92m[>] How often do you want to change your IP? (in seconds) \xBB\033[0m\033[1;77m "))
81-
if time_interval <= 0:
82-
raise Exception
83-
84-
except Exception:
85-
print("\033[1;91m[!]\033[1;93m Time interval must be a positive integer.\033[0m")
86-
return
87-
88-
print(f"\033[1;91m[!]\033[1;93m Your IP address will be changed every {time_interval} seconds until you stop the script!")
89-
print("\033[1;91m[!]\033[1;93m Press Ctrl + C to stop.")
90-
time.sleep(1)
91-
92-
print("\033[1;34m[*] Checking for Tor connection...\033[0m")
93-
94-
tor_status = subprocess.run(["sudo", "service", "tor", "status"], capture_output = True, text = True)
95-
if "Active: active" in tor_status.stdout:
96-
print("\033[1;92m[+] Tor is already running.\033[0m")
97-
98-
else:
99-
print("\033[1;93m[-] Tor is not running.\033[0m")
100-
print("\033[1;34m[*] Starting Tor service...\033[0m")
101-
subprocess.run("sudo service tor start", shell = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
102-
time.sleep(3)
103-
104-
while True:
105-
try:
106-
response = requests.get(url, proxies = proxy)
107-
changed_ip = response.json().get('origin')
108-
print(f"\033[1;92m[+] Your IP has been changed to {changed_ip}\033[0m")
109-
110-
except Exception:
111-
print(f"\033[1;91m[-] Error!\033[1;93m Failed to change IP. Retrying...\033[0m")
112-
113-
time.sleep(time_interval)
114-
subprocess.run("sudo service tor reload", shell = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
115-
116-
except KeyboardInterrupt:
117-
print("\n\033[1;91m[!]\033[1;93m Exiting...\033[0m")
118-
print("\033[1;34m[*] Stopping Tor service...\033[0m")
119-
subprocess.run("sudo service tor stop", shell = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
16+
if os.name == 'nt':
17+
run_windows_script()
18+
elif os.name == 'posix':
19+
run_linux_script()
20+
else:
21+
print("Unsupported operating system")
22+
sys.exit(1)
12023

12124
if __name__ == '__main__':
12225
main()

README.md

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
12
# Auto Change Tor IP
23

3-
* This tool automates the process of periodically changing the Tor IP address.
4-
* Basically it enters a loop where it continuously fetches a new IP address through Tor proxies.
5-
* Restart tor service, and you got a new IP :D
4+
This tool automates the process of periodically changing the Tor IP address.
5+
Basically, it enters a loop where it continuously fetches a new IP address through Tor proxies.
6+
Restart the Tor service, and you got a new IP :D
67

7-
> [!IMPORTANT]
8-
> This version of the tool is currently supported only on Unix-like operating systems.
8+
> **IMPORTANT**
9+
> This version of the tool is supported on both Linux and Windows operating systems.
910
10-
## Usage
11+
## Features
12+
- Automatic Tor IP address change.
13+
- Supports both Linux and Windows.
14+
- Requires Tor service to be running.
15+
16+
## Installation
17+
18+
### Linux
1119

1220
1. Clone the repository:
1321

@@ -27,11 +35,71 @@
2735
pip install -r requirements.txt
2836
```
2937

30-
4. Run the script:
38+
4. Install Tor (if not already installed):
39+
40+
For Ubuntu/Debian-based systems, run:
41+
42+
```bash
43+
sudo apt update
44+
sudo apt install tor
45+
```
46+
47+
5. Run the script with root privileges:
3148

3249
```bash
3350
sudo python3 IP-Changer.py
3451
```
35-
<br>
52+
53+
### Windows
54+
55+
1. Clone the repository:
56+
57+
```bash
58+
git clone https://github.com/isPique/Tor-IP-Changer.git
59+
```
60+
61+
2. Navigate to the project directory:
62+
63+
```bash
64+
cd Tor-IP-Changer
65+
```
66+
67+
3. Install required libraries:
68+
69+
```bash
70+
pip install -r requirements.txt
71+
```
72+
73+
4. Install Tor:
74+
75+
Download and install Tor from the official website: [Tor Browser Download](https://www.torproject.org/download/)
76+
77+
After installing, you should be able to start the Tor service.
78+
79+
5. Run the script:
80+
81+
Open Command Prompt (CMD) and navigate to the directory where the script is located, then run:
82+
83+
```bash
84+
python IP-Changer.py
85+
```
86+
87+
## Usage
88+
89+
1. The script will automatically detect your operating system (Linux or Windows) and run the appropriate version.
90+
2. Once the script is running, it will periodically change your Tor IP address.
91+
3. The IP address will be changed at the interval you specify (in seconds).
92+
4. To stop the script, press `Ctrl + C` in the terminal.
93+
94+
## Additional Information
95+
96+
- On Linux, you may need to run the script with `sudo` privileges to interact with the Tor service.
97+
- On Windows, make sure that the Tor service is running and accessible. If you face issues, ensure that the Tor executable is correctly set up in your system's PATH.
98+
99+
## License
100+
101+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
102+
103+
## Screenshot
36104
37105
![Terminal](https://github.com/isPique/Tor-IP-Changer/blob/main/Terminal.jpg)

scr/main_linux.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import subprocess
2+
import requests
3+
import time
4+
import sys
5+
import os
6+
import platform
7+
8+
def display_banner():
9+
os.system('cls' if platform.system() == 'Windows' else 'clear') # Clear the screen based on OS
10+
DEFAULT, GREEN, RED, YELLOW, YELLOW2, ITALIC, BLINK = '\033[0m', '\033[1;92m', '\033[1;31m', '\033[1;33m', '\033[1;93m', '\033[3m', '\033[5m'
11+
12+
print('''
13+
{4} █████ ███████████ █████████ █████ █████ █████████ ██████ █████ █████████ ██████████ ███████████{0}
14+
{4}░░███ ░░███░░░░░███ ███░░░░░███░░███ ░░███ ███░░░░░███ ░░██████ ░░███ ███░░░░░███░░███░░░░░█░░███░░░░░███{0}
15+
{4} ░███ ░███ ░███ ███ ░░░ ░███ ░███ ░███ ░███ ░███░███ ░███ ███ ░░░ ░███ █ ░ ░███ ░███{0}
16+
{4} ░███ ░██████████ ░███ ░███████████ ░███████████ ░███░░███░███ ░███ ░██████ ░██████████{0}
17+
{4} ░███ ░███░░░░░░ ░███ ░███░░░░░███ ░███░░░░░███ ░███ ░░██████ ░███ █████ ░███░░█ ░███░░░░░███{0}
18+
{4} ░███ ░███ ░░███ ███ ░███ ░███ ░███ ░███ ░███ ░░█████ ░░███ ░░███ ░███ ░ █ ░███ ░███{0}
19+
{4} █████ █████ ░░█████████ █████ █████ █████ █████ █████ ░░█████ ░░█████████ ██████████ █████ █████{0}
20+
{4}░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░{0}
21+
22+
{1}{5}================ {1}{5}======================
23+
{3}{5}Version: {2}1.0{2} {3}{5}Code Author: {2}isPique
24+
{1}{5}================ {1}{5}======================
25+
26+
{3}{5}GitHub Profile {2}{6}:{0}{1} https://github.com/isPique{0}
27+
'''.format(DEFAULT, GREEN, RED, YELLOW, YELLOW2, ITALIC, BLINK))
28+
29+
def install_tor():
30+
if platform.system() == "Windows":
31+
tor_installed = subprocess.run(["where", "tor"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0
32+
if not tor_installed:
33+
print("\033[1;91m[!]\033[1;93m Tor is not installed. Please install Tor from https://www.torproject.org/ and ensure it's added to your PATH.\033[0m")
34+
return False
35+
else:
36+
tor_installed = subprocess.run(["which", "tor"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0
37+
if not tor_installed:
38+
print("\033[1;91m[!]\033[1;93m Tor is not installed. Installing it...\033[0m")
39+
if subprocess.run(["sudo", "apt", "install", "tor", "-y"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode != 0:
40+
print("\033[1;91m[!]\033[1;93m Failed to install Tor!\n\033[1;91m[!]\033[1;93m Please check your network connection.\033[0m")
41+
return False
42+
else:
43+
print("\033[1;92m[+] Tor has been successfully installed.\033[0m")
44+
return True
45+
46+
def main():
47+
url = "https://httpbin.org/ip"
48+
proxy = {
49+
'http': 'socks5://127.0.0.1:9050',
50+
'https': 'socks5://127.0.0.1:9050'
51+
}
52+
53+
try:
54+
print("\033[1;34m[*] Checking if Tor is installed...\033[0m")
55+
time.sleep(1)
56+
if not install_tor():
57+
return
58+
else:
59+
print("\033[1;92m[+] Tor is already installed.\033[0m")
60+
time.sleep(1)
61+
62+
display_banner()
63+
64+
try:
65+
version_info = subprocess.run("tor --version", capture_output=True, text=True, shell=True)
66+
version = version_info.stdout.split('\n')[0].split(' ')[2]
67+
print(f"\033[1;34m[*] Your Tor version is: {version}\033[0m")
68+
except Exception:
69+
pass
70+
71+
try:
72+
response = requests.get(url)
73+
current_ip = response.json()["origin"]
74+
print(f"\033[1;34m[*] Your current IP address is: {current_ip}\033[0m")
75+
except:
76+
pass
77+
78+
try:
79+
time_interval = int(input("\033[1;92m[>] How often do you want to change your IP? (in seconds) \xBB\033[0m\033[1;77m "))
80+
if time_interval <= 0:
81+
raise Exception
82+
83+
except Exception:
84+
print("\033[1;91m[!]\033[1;93m Time interval must be a positive integer.\033[0m")
85+
return
86+
87+
print(f"\033[1;91m[!]\033[1;93m Your IP address will be changed every {time_interval} seconds until you stop the script!")
88+
print("\033[1;91m[!]\033[1;93m Press Ctrl + C to stop.")
89+
time.sleep(1)
90+
91+
print("\033[1;34m[*] Checking for Tor connection...\033[0m")
92+
tor_status = subprocess.run(["tasklist", "/FI", "imagename eq tor.exe"], capture_output=True, text=True, shell=True)
93+
if "tor.exe" in tor_status.stdout:
94+
print("\033[1;92m[+] Tor is already running.\033[0m")
95+
else:
96+
print("\033[1;93m[-] Tor is not running.\033[0m")
97+
print("\033[1;34m[*] Starting Tor service...\033[0m")
98+
subprocess.run("start tor", shell=True)
99+
time.sleep(3)
100+
101+
while True:
102+
try:
103+
response = requests.get(url, proxies=proxy)
104+
changed_ip = response.json().get('origin')
105+
print(f"\033[1;92m[+] Your IP has been changed to {changed_ip}\033[0m")
106+
except Exception:
107+
print(f"\033[1;91m[-] Error!\033[1;93m Failed to change IP. Retrying...\033[0m")
108+
109+
time.sleep(time_interval)
110+
subprocess.run("start tor", shell=True)
111+
112+
except KeyboardInterrupt:
113+
print("\n\033[1;91m[!]\033[1;93m Exiting...\033[0m")
114+
print("\033[1;34m[*] Stopping Tor service...\033[0m")
115+
subprocess.run("taskkill /IM tor.exe /F", shell=True)
116+
117+
if __name__ == '__main__':
118+
main()

0 commit comments

Comments
 (0)