forked from serhattsnmz/Tardigrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tardigrade.py
77 lines (64 loc) · 2.63 KB
/
tardigrade.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
import requests
import json
import re
import argparse
from pprint import pprint
from prettytable import PrettyTable
class Parse:
def __init__(self):
self.args = ""
self.subdomains = []
self.linkler = []
self.result = []
self.parse_args()
self.read_subdomains()
self.parse()
def parse_args(self):
parser = argparse.ArgumentParser(description="Fetch and try all the links in a url address.")
parser.add_argument("-d", "--domain", metavar="", required=True, help="Domain name")
parser.add_argument("-t", "--text", metavar="", required=True, help="Subdomain file", )
parser.add_argument("-v", "--verbose", default="False", choices=("True", "False"), metavar="", help="See the results in real time")
parser.add_argument("-s", "--savefile", default="False", choices=("True", "False"), metavar="", help="Save result to json file")
self.args = parser.parse_args()
def parse(self):
site = "http://" + str(self.args.domain).replace("http://", "").replace("https://", "")
print(site)
r = requests.get(site)
pattern = "[a-zA-Z0-9-_]+\.com|[a-zA-Z0-9-_]+\.net|[a-zA-Z0-9-_]+\.org"
regex = re.compile(pattern)
self.linkler = list(set(regex.findall(r.text)))
def read_subdomains(self):
with open(self.args.text) as f:
self.subdomains = f.read().split("\n")
def try_subdomains(self):
for link in self.linkler:
for sub in self.subdomains:
domain = f"http://{sub}.{link}"
try:
r = requests.get(domain, stream=True)
if r.status_code == 200:
self.result.append({
"ip_address" : r.raw._connection.sock.getpeername()[0],
"domain_name" : domain
})
if self.args.verbose == "True":
print("Connection : " + domain)
except:
if self.args.verbose == "True":
print("Error : " + domain)
def save_file(self):
if self.args.savefile == "True":
with open("result.json", "w") as f:
json.dump(self.result, f)
print("File created.")
def write_result(self):
p = PrettyTable()
p.field_names = ["Domain Name", "IP Address"]
for res in self.result:
p.add_row([res["domain_name"],res["ip_address"]])
print(p)
if __name__ == "__main__":
p = Parse()
p.try_subdomains()
p.write_result()
p.save_file()