Skip to content

Commit

Permalink
update version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
noobpk committed Feb 6, 2021
1 parent 71cabe9 commit c4a26b4
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 57 deletions.
204 changes: 147 additions & 57 deletions autorip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import time
import os
import sys
import socks
import socket
import urllib.request
from log import *

print ('''\033[1;31m \n
_| _| _| _|
Expand All @@ -14,7 +18,7 @@
''')

print ("\033[1;34m[*]___author___: @noobpk\033[1;37m")
print ("\033[1;34m[*]___version___: 1.1.1\033[1;37m")
print ("\033[1;34m[*]___version___: 1.2\033[1;37m")
print ("")


Expand All @@ -26,160 +30,246 @@ def detect_platform():
'linux2' : 'Linux',
'darwin' : 'OS X',
}
print ("\033[1;32m[+] Detect Platform\033[1;37m")
logger.info("[*] Detect Platform")
if sys.platform not in platforms:
print ("\033[1;31m[x] Your platform currently does not support\033[1;31m")
logger.error("[x_x] Your platform currently does not support.")
sys.exit(0)
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def check_exists_tor_ip(ipTor):
with open ('listip.txt', 'r') as read_obj:
for line in read_obj:
if ipTor in line:
return True
else:
return False

def check_runon_osx():
try:
print ("\033[1;32m[+] Check Requirement\033[1;37m")
logger.info("[+] Check Requirement")
istor = os.system('command -v tor 1> /dev/null')
istorsocks = os.system ('command -v torsocks 1> /dev/null')
isprivoxy = os.path.isdir("/usr/local/Cellar/privoxy")
file_listip = os.path.isfile("listip.txt")
if (istor != 0):
print ("\033[1;32m[+] Installing Tor\033[1;37m")
logger.info("Installing Tor...")
os.system('brew install tor')
check_runon_osx()
if (istorsocks != 0):
print ("\033[1;32m[+] Installing TorSocks\033[1;37m")
logger.info("[+] Installing TorSocks...")
os.system('brew install torsocks')
check_runon_osx()
if (isprivoxy == False):
print ("\033[1;32m[+] Installing Privoxy\033[1;37m")
logger.info("[+] Installing Privoxy...")
os.system('brew install privoxy')
check_runon_osx()
if (file_listip == False):
logger.info("[+] Creating File listip.txt")
open("listip.txt", "w")
check_runon_osx()
else:
print ("\033[1;34m[!] Tor has been install\033[1;37m")
print ("\033[1;34m[!] TorSocks has been install\033[1;37m")
print ("\033[1;34m[!] Privoxy has been install\033[1;37m")
logger.info("[*] Tor has been install")
logger.info("[*] TorSocks has been install")
logger.info("[*] Privoxy has been install")
logger.info("[*] File listip.txt has been created")
startservice_osx()
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def startservice_osx():
try:
print ("\033[1;34m[!] Current IP Addresss\033[1;37m")
logger.info("[*] Current IP Addresss")
currentip = os.system("wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
print ("\033[1;32m[+] Start service Tor\033[1;37m")
logger.info("[*] Start service Tor")
os.system("brew services start tor")
time.sleep(2)
print ("\033[1;32m[+] Start service Privoxy\033[1;37m")
logger.info("[*] Start service Privoxy")
os.system("brew services start privoxy")
time.sleep(2)
print ("\033[1;34m[!] Change your SOCKES to 127.0.0.1:9050\033[1;37m")
print ("\033[1;32m[+] Set time stamp\033[1;37m")
logger.info("[*] Change your SOCKES to 127.0.0.1:9050")
logger.info("[+] Set time stamp")
sec = int(input("[?] Time to auto change ip by second (default 600s):") or "600")
loop = int(input("[?] Number of loop (default 144):") or "144")
for i in range(loop):
print ("\033[1;32m[+] Change New IP\033[1;37m")
logger.info("[*] Change New IP:")
os.system("brew services restart tor")
time.sleep(2)
print("\033[1;32m[+] Successfully - Your IP has been Changed\033[1;37m")
print ("\033[1;34m[!] New IP Addresss:\033[1;37m")
# currentip = os.system("torsocks wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
#currentip = os.system("torsocks wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
url = 'http://ipecho.net/plain'
request = urllib.request.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib.request.urlopen(request)
newip = response.read().decode('utf-8')
if check_exists_tor_ip(newip):
restart_tor_service()
else:
f = open('listip.txt', 'a+')
f.write(newip + '\n')
logger.info("[*] Successfully - Your IP has been Changed")
logger.info("[*] New IP Addresss:")
print(newip)
time.sleep(sec)
print ("\033[1;31m[#] The loop has finished refreshing it\033[1;37m")
logger.info("[#] The loop has finished refreshing it")
stopservice_osx()
except Exception as e:
raise e

logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def restart_tor_service_osx():
logger.warning("Your IP Already Exist - Request New IP")
os.system("brew services restart tor")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
url = 'http://ipecho.net/plain'
request = urllib.request.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib.request.urlopen(request)
newip = response.read().decode('utf-8')
if check_exists_tor_ip(newip):
restart_tor_service()
else:
f = open('listip.txt', 'a+')
f.write(newip + '\n')
logger.info("[*] Successfully - Your IP has been Changed")
logger.info("[*] New IP Addresss:")
print(newip)

def stopservice_osx():
try:
print ("\033[1;32m[+] Stop service Tor\033[1;37m")
logger.info("[+] Stop service Tor")
os.system("brew services stop tor")
time.sleep(2)
print ("\033[1;32m[+] Stop service Privoxy\033[1;37m")
logger.info("[+] Stop service Privoxy")
os.system("brew services stop privoxy")
os.system("clear")
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def check_runon_linux():
try:
print ("\033[1;32m[+] Check Requirement\033[1;37m")
logger.info("[+] Check Requirement")
istor = os.system('command -v tor 1> /dev/null')
istorsocks = os.system('command -v torsocks 1> /dev/null')
isprivoxy = os.system('command -v privoxy 1> /dev/null')
file_listip = os.path.isfile("listip.txt")
if (os.geteuid() != 0):
logger.error("[x_x] You need to have root privileges to run this script")
sys.exit(0)
if (istor != 0):
print ("\033[1;32m[+] Installing Tor\033[1;37m")
os.system('apt-get install tor')
logger.info("[+] Installing Tor")
os.system('apt-get install tor -y')
check_runon_linux()
if (istorsocks != 0):
print ("\033[1;32m[+] Installing TorSocks\033[1;37m")
os.system('apt-get install torsocks')
logger.info("[+] Installing TorSocks")
os.system('apt-get install torsocks -y')
check_runon_linux()
if (isprivoxy != 0):
print ("\033[1;32m[+] Installing Privoxy\033[1;37m")
os.system('apt-get install privoxy')
logger.info("[+] Installing Privoxy")
os.system('apt-get install privoxy -y')
check_runon_linux()
if (file_listip == False):
logger.info("[+] Creating File listip.txt")
open("listip.txt", "w")
check_runon_linux()
else:
print ("\033[1;34m[!] Tor has been install\033[1;37m")
print ("\033[1;34m[!] TorSocks has been install\033[1;37m")
print ("\033[1;34m[!] Privoxy has been install\033[1;37m")
logger.info("[*] Tor has been install")
logger.info("[*] TorSocks has been install")
logger.info("[*] Privoxy has been install")
logger.info("[*] File listip.txt has been created")
startservice_linux()
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def startservice_linux():
try:
print ("\033[1;34m[!] Current IP Addresss\033[1;37m")
logger.info("[*] Current IP Addresss")
currentip = os.system("wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
print ("\033[1;32m[+] Start service Tor\033[1;37m")
logger.info("[*] Start service Tor")
os.system("service tor start")
time.sleep(2)
print ("\033[1;32m[+] Start service Privoxy\033[1;37m")
logger.info("[*] Start service Privoxy")
os.system("service privoxy start")
time.sleep(2)
print ("\033[1;34m[!] Change your SOCKES to 127.0.0.1:9050\033[1;37m")
print ("\033[1;32m[+] Set time stamp\033[1;37m")
logger.info("[*] Change your SOCKES to 127.0.0.1:9050")
logger.info("[*] Set time stamp")
sec = int(input("[?] Time to auto change ip by second (default 600s):") or "600")
loop = int(input("[?] Number of loop (default 144):") or "144")
for i in range(loop):
print ("\033[1;32m[+] Change New IP\033[1;37m")
logger.info("[*] Change New IP:")
os.system("service tor restart")
time.sleep(2)
print("\033[1;32m[+] Successfully - Your IP has been Changed\033[1;37m")
print ("\033[1;34m[!] New IP Addresss:\033[1;37m")
currentip = os.system("torsocks wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
# currentip = os.system("torsocks wget -qO- http://ipecho.net/plain 2> /dev/null ; echo")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
url = 'http://ipecho.net/plain'
request = urllib.request.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib.request.urlopen(request)
newip = response.read().decode('utf-8')
if check_exists_tor_ip(newip):
restart_tor_service()
else:
f = open('listip.txt', 'a+')
f.write(newip + '\n')
logger.info("[*] Successfully - Your IP has been Changed")
logger.info("[*] New IP Addresss:")
print(newip)
time.sleep(sec)
print ("\033[1;31m[#] The loop has finished refreshing it\033[1;37m")
logger.info("[#] The loop has finished refreshing it")
stopservice_linux()
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def restart_tor_service_linux():
logger.warning("Your IP Already Exist - Request New IP")
os.system("service tor restart")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
url = 'http://ipecho.net/plain'
request = urllib.request.Request(url)
request.add_header('Cache-Control','max-age=0')
response = urllib.request.urlopen(request)
newip = response.read().decode('utf-8')
if check_exists_tor_ip(newip):
restart_tor_service()
else:
f = open('listip.txt', 'a+')
f.write(newip + '\n')
logger.info("[*] Successfully - Your IP has been Changed")
logger.info("[*] New IP Addresss:")
print(newip)

def stopservice_linux():
try:
print ("\033[1;32m[+] Stop service Tor\033[1;37m")
logger.info("[*] Stop service Tor")
os.system("service tor stop")
time.sleep(2)
print ("\033[1;32m[+] Stop service Privoxy\033[1;37m")
logger.info("[*] Stop service Privoxy")
os.system("service privoxy stop")
os.system("clear")
except Exception as e:
raise e
logger.error("[x_x] Something went wrong, please check your error message.\n Message - {0}".format(e))

def main():

try:
detect_platform()
if (sys.platform == 'darwin'):
print ("\033[1;34m[*] Darwin - MAC OS-X\033[1;37m")
logger.info("[*] Darwin - MAC OS-X")
check_runon_osx()
if (sys.platform == 'linux') | (sys.platform == 'linux1') | (sys.platform == 'linux2'):
print ("\033[1;34m[*] Linux - KALI LINUX - UBUNTU\033[1;37m")
logger.info("[*] Linux - KALI LINUX - UBUNTU")
check_runon_linux()
except KeyboardInterrupt:
print ("\033[1;31m[#] KeyboardInterrupt\033[1;37m")
logger.warning("[#] KeyboardInterrupt")
if (sys.platform == 'darwin'):
stopservice_osx()
if (sys.platform == 'linux') | (sys.platform == 'linux1') | (sys.platform == 'linux2'):
stopservice_linux()

if __name__ == '__main__':
if sys.version_info < (3,0):
print("[x_x] Autorip requires Python 3.x")
logger.error("[x_x] Autorip requires Python 3.x")
else:
main()
33 changes: 33 additions & 0 deletions log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging
from colorlog import ColoredFormatter


def setup_logging():
logger = logging.getLogger()
logger.setLevel(logging.INFO)
color_formatter = ColoredFormatter(
"%(log_color)s[%(asctime)s] [%(levelname)-4s]%(reset)s - %(message)s",
datefmt='%d-%m-%y %H:%M:%S',
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'bold_yellow',
'ERROR': 'bold_red',
'CRITICAL': 'bold_red',
},
secondary_log_colors={},
style='%')
logging_handler = logging.StreamHandler()
logging_handler.setFormatter(color_formatter)
logger.addHandler(logging_handler)
#record logg
file_handler = logging.FileHandler('errors.log')
file_handler.setLevel(logging.ERROR)
file_format = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(file_format)
logger.addHandler(file_handler)

# setup logging for script
setup_logging()
logger = logging.getLogger(__name__)

0 comments on commit c4a26b4

Please sign in to comment.