forked from jevalenciap/iptodomain
-
Notifications
You must be signed in to change notification settings - Fork 10
/
iptodomain.py
142 lines (112 loc) · 3.87 KB
/
iptodomain.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
140
141
142
import json
import urllib
import time
import argparse
import sys
parser = argparse.ArgumentParser(
description='This tool allow to extract domains from IP information on Virustotal and save the output in a file. You have to set up the IP range where you like to extract domain or subdomain. Additionally it is neccesary set up your VirusTotal API key in the code.')
parser.add_argument('-i', action="store", dest='FIRST_IP', help='The First IP of the range that you want to scan')
parser.add_argument('-f', action="store", dest='LAST_IP', help='The Last IP of the range that you want to scan.')
parser.add_argument('-w', action="store", dest='File2',
help='Please enter the file name where report with all domains and its IPs are going to save.')
parser.add_argument('-o', action="store", dest='File1',
help='Please enter the file name where the all domains found are going to save. ')
parser.add_argument('-v', action="store_false", dest='Verbose', default=True,
help='It shows more information while you are scanning.')
parser.add_argument('-r', action="store", dest='File3',
help='Please enter the name of the final Report without duplicate domains results')
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
argd = parser.parse_args()
args = vars(args)
if args['FIRST_IP'] is None:
print "Enter the IP information example... 18.2.4.4"
sys.exit()
else:
fi = args['FIRST_IP']
if args['LAST_IP'] is None:
print "Enter the IP information example... 18.2.4.10"
sys.exit()
else:
li = args['LAST_IP']
if argd.Verbose:
cp = 'False'
else:
cp = 'True'
f1 = ''
f2 = ''
if args['File1'] is None:
if args['File2'] is None:
print "Enter -w or -o in orden to save the results in a file and no lose the progress if there is a problem"
sys.exit()
else:
ctr = 1
f2 = args['File2']
else:
f1 = args['File1']
if args['File2'] is None:
ctr = 0
else:
ctr = 2
f2 = args['File2']
oa = False
if args['File3'] is not None:
f3 = args['File3']
oa = True
def ipRange(start_ip, end_ip):
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
temp = start
ip_ange = [start_ip]
while temp != end:
start[3] += 1
for i in (3, 2, 1):
if temp[i] == 256:
temp[i] = 0
temp[i - 1] += 1
ip_ange.append(".".join(map(str, temp)))
return ip_ange
if f1 != '':
file1 = open(f1, "a")
if f2 != '':
file2 = open(f2, "a")
if oa:
file3 = open(f3, "w")
s = list()
ok = 0
ip_range = ipRange(fi, li)
for ip in ip_range:
url = 'https://www.virustotal.com/vtapi/v2/ip-address/report'
parameters = {'ip': ip,
'apikey': '3c052e9a7339f3a73f00bd67baea747e47f59ee6c1596e59590fd953d00ce519'} # please enter your Virustotal API key, if you do not have one, there is a free API... sign up to Virustotal
response = urllib.urlopen('%s?%s' % (url, urllib.urlencode(parameters))).read()
response_dict = json.loads(response)
if cp == 'True':
print 'Scanning IP: ', ip
cod = (response_dict.get("response_code"))
if cod == 1:
u = (response_dict.get("resolutions"))
i = len(u)
while i > 0:
i -= 1
b = response_dict.get("resolutions")[i].get("hostname")
s.append(b)
m = list(set(s))
print b
if ctr == 2:
file2.write(ip + ' ' + b + '\n')
file1.write(b + '\n')
elif ctr == 1:
file2.write(ip + ' ' + b + '\n')
else:
file1.write(b + '\n')
time.sleep(15)
if oa:
qw = 0
owa = list(set(m))
ot = len(owa) - 1
while qw < ot:
file3.write(m[qw] + '\n')
qw += 1