-
Notifications
You must be signed in to change notification settings - Fork 1
/
rev.py
139 lines (121 loc) · 4.3 KB
/
rev.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
#@CallMeRep
#Reverse IP With CIDR Ranger Support Type of list like
#google.com
#google.com/16
#https://google.com
#1.1.1.1
#1.1.1.1/16
#https://google.com/asumemek/kontolgoreng
#if you want add banned subdomains just input the subdomain. in banned_subdomains.txt
#if your list already have cidr just input the cidr "auto"
#if you dont want using cidr/range ip just input "0"
from threading import *
from threading import Thread
from queue import Queue
from socket import gethostbyname
import requests,re ,os, socket, os, urllib3, validators
from urllib.parse import urlparse
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from netaddr import IPNetwork
class Worker(Thread):
def __init__(self, tasks):
Thread.__init__(self)
self.tasks = tasks
self.daemon = True
self.start()
def run(self):
while True:
func, args, kargs = self.tasks.get()
try: func(*args, **kargs)
except Exception as e: print(e)
self.tasks.task_done()
class ThreadPool:
def __init__(self, num_threads):
self.tasks = Queue(num_threads)
for _ in range(num_threads): Worker(self.tasks)
def add_task(self, func, *args, **kargs):
self.tasks.put((func, args, kargs))
def wait_completion(self):
self.tasks.join()
class RevIP:
def __init__(self, iplist):
self.result = []
self.ip = iplist
self.cidr = input("cidr : ")
self.thread = input("thread : ")
def domainToIP(self):
try:
if self.ip.startswith( "http" ) or self.ip.startswith( "https" ):
self.ip = urlparse(self.ip).netloc
if "/" in self.ip:
if self.ip.endswith("/"): self.ip = self.ip[:-1]
cidrf = re.findall("/(.*)", self.ip)
if cidrf: self.cidr = cidrf[0]
ipf = re.findall("(.*)/", self.ip)
if ipf : self.ip = ipf[0]
self.ip = socket.gethostbyname( self.ip )
except:
pass
def rev(self,ips):
head = {
'Origin': 'https://www.ipaddress.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.107 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {"host" : ips}
try:
r = requests.post("https://www.ipaddress.com/reverse-ip-lookup", data=data, headers=head, timeout=25, verify=False, allow_redirects=False).text
if "We found no hostnames for " not in r:
selector = re.findall("site\/(.*?)\"", r)
print(f"ip : {ips} result: {len(selector)}")
for results in selector:
results = results.replace("\n", "").replace("\r", "")
banSubdo = open('banned_subdomains.txt', 'r').read().splitlines()
site = re.sub(r'[^A-Za-z0-9.\\-]','', results)
for ban in banSubdo:site = site.replace(ban, "")
if site not in self.result:
self.result.append(site)
open( "reversed.txt", "a" ).write( site + "\n" )
return self.result
else:
print(f"ip : {ips} BAD-IPS [No-Results]")
except Exception as e:
print(e)
pass
def ranger(self, cidr):
pool = ThreadPool(int(self.thread))
print(f"( ip : {self.ip} cidr : {cidr} )")
for ip in IPNetwork(f"{self.ip}/{cidr}"):
pool.add_task( self.rev, ip )
print(f"list: {self.ip}/{cidr} total result: {len(self.result)}")
pool.wait_completion()
def execute(self):
pool2 = ThreadPool(int(self.thread))
for url in self.ip:
self.ip = url
self.domainToIP()
if self.cidr != "0" or self.cidr == "auto":
self.ranger(self.cidr)
else:
pool2.add_task( self.rev, self.ip )
pool2.wait_completion()
print("Done Script")
if __name__ == '__main__':
try:
linux = 'clear'
windows = 'cls'
os.system([linux,windows][os.name == 'nt'])
except:
os.system(linux)
try:
print(f"""
Simple Reverse IP Lookup ipaddress.com + Auto Range IP MultiThreaded
Input CIDR "0" to not using The Range IP
Credits : @CallMeRep
""")
list = open(input("list : "), encoding="utf8" ).read().splitlines()
RevIP(list).execute()
except Exception as f:
print(f)
pass