-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathIPChanger.py
123 lines (106 loc) · 4.23 KB
/
IPChanger.py
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
118
119
120
121
122
123
# IPChanger.py
# https://github.com/hevnsnt/IPChanger
# Released under GPL 3.0
#
# Usage: python3 IPChanger.py
#
# Or
# import IPChanger
# oldip, newip = IPChanger.getNewIP(display=True) # if you want output
#
# use proxychains to run whatever you are doing
import requests
import sys, os
from time import sleep
from stem import Signal
from stem.control import Controller
from fake_useragent import UserAgent
from colorama import Fore, Back, Style, init
from signal import signal, SIGINT
###########################Basic Setup########################################
proxies = {
'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'
} # This is for the local TOR proxy
IPCheckURL = 'https://icanhazip.com' # URL to determine IP address
headers = { 'User-Agent': UserAgent().random }
torpassword = ""
###############################################################################
def banner():
os.system('clear')
data = '''
::::::::::: :::::::::
:+: :+: :+:
+:+ +:+ +:+
+#+ +#++:++#+
+#+ +#+
#+# #+#
########### ###
:::::::: ::: ::: ::: :::: ::: :::::::: :::::::::: :::::::::
:+: :+: :+: :+: :+: :+: :+:+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+
+#+ +#++:++#++ +#++:++#++: +#+ +:+ +#+ :#: +#++:++# +#++:++#:
+#+ +#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+# +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+#+# #+# #+# #+# #+# #+#
######## ### ### ### ### ### #### ######## ########## ### ###
...use it for things...
'''
print(data)
def validateEnv():
#Lets make sure everything is safe before we start
if sys.platform != 'linux':
print(' [' + Fore.RED + '!' + Style.RESET_ALL + '] This script requires Linux')
sys.exit(0)
else:
print(f' [' + Fore.GREEN +'+' + Style.RESET_ALL + '] OS Check:' + Fore.GREEN + f' {sys.platform}' + Style.RESET_ALL)
try:
doIPAddressStuff()
print(' [' + Fore.GREEN +'+' + Style.RESET_ALL + '] TOR Proxy: ' + Fore.GREEN + 'Responding' + Style.RESET_ALL)
except:
sys.exit(0)
def doIPAddressStuff():
# This connects to the local TOR proxy and requests a new TOR exit node
# It only makes the request, often you will get the same exit node returned
# as TOR assigns node based on "best" route
try:
with Controller.from_port(port = 9051) as c:
c.authenticate(password = torpassword)
c.signal(Signal.NEWNYM)
except:
print(' [' + Fore.RED + '!' + Style.RESET_ALL + '] Local TOR proxy not responding')
print(' [+] See READ.ME for TOR Proxy Configuration Instructions')
sys.exit(0)
def getNewIP(display=False):
# This uses the 'IPCheckURL' to determine what our current IP address is
# and then uses the getNewIP() function to get a new one
headers = { 'User-Agent': UserAgent().random }
count = 1
while True:
try:
currentIP = requests.get(IPCheckURL, proxies=proxies, headers=headers, timeout=3).text
oldIPaddy = currentIP
while currentIP == oldIPaddy:
if display: print('\r [' + Fore.GREEN +'+' + Style.RESET_ALL + f'] [Getting new IP: {count}]', end ='')
count = count + 1
doIPAddressStuff()
currentIP = requests.get(IPCheckURL, proxies=proxies, headers=headers, timeout=3).text
if display: print(Style.BRIGHT + Fore.BLACK + f'\n [+] Obtained new IP Address: {currentIP}' + Style.RESET_ALL)
except KeyboardInterrupt:
sys.exit(0)
except:
if display: print('\r [' + Fore.RED + '!' + Style.RESET_ALL + f'] Connection Error to {IPCheckURL}, retrying', end='')
sleep(3)
continue #quality code right here
break
return oldIPaddy.strip(), currentIP.strip()
def handler(signal_received, frame):
# Catches CTRL-C // Handle any cleanup here
print('\n [!] CTRL-C detected. Exiting gracefully\n')
sys.exit(0)
if __name__ == "__main__":
signal(SIGINT, handler)
banner()
validateEnv() # Make sure we have correct environment
oldip, newip = getNewIP(display=True)
print(f'\nOld IPaddress: {oldip}')
print(f'New Ipaddress: {newip}')