-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathget_ips.py
93 lines (75 loc) · 2.53 KB
/
get_ips.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
#coding:utf-8
#author:w8ay
#@date:2018年5月22日 09:43:23
"""
w8fuckcdn 1.0
(https://x.hacking8.com)
获取子域名的IP段
"""
import sys; sys.path.append('./thirdparty/subdomainBrute')
from thirdpart.subdomainBrute import subdomain
from thirdpart.IPy import IP
import argparse
import urlparse
import socket
def get_url_host(url):
host = urlparse.urlparse(url)[1]
if ':' in host:
host = host[:host.find(':')]
return host
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='powered by w8ay <mail:[email protected]> ')
parser.add_argument('-d', dest="domain" ,type=str, default='')
parser.add_argument('-f', metavar='FILE',dest="filename" ,type=str, default='')
parser.add_argument('-o', dest="output" ,type=str, default='output.txt')
parser.add_argument('--ips', dest="ips", default=False, action='store_true')
if len(sys.argv) == 1:
sys.argv.append('-h')
args = parser.parse_args()
if args.domain:
host = args.domain
result = subdomain.Interface(host)
if result is None or not len(result):
print("No vaild IP found")
exit()
ips = list(set(result))
netmask='255.255.255.0'
ip_range_list = [str(IP(ip).make_net(netmask)) for ip in ips]
ips = list(set(ip_range_list))
info = '\n'.join(ips)
filename = 'target.log'
with open(filename, 'w') as f:
f.write(info)
print '[*] Info is saved into %s'%(filename)
exit()
filename = args.filename
output = args.output
if filename:
with open(filename) as f:
flines = f.readlines()
result = set()
I = 0
count = len(flines)
print "total:%d " % (count)
for line in flines:
host = get_url_host(line).strip()
try:
ip = socket.gethostbyname(host)
result.add(ip)
except Exception,e:
print e,host
I = I + 1
if I%300 == 0:
print "works 300 ..."
result = list(result)
print "process finished,building..."
if args.ips:
netmask='255.255.255.0'
ip_range_list = [str(IP(ip).make_net(netmask)) for ip in result]
ips = list(set(ip_range_list))
info = '\n'.join(ips)
else:
info = '\n'.join(result)
with open(output, 'w') as f:
f.write(info)
print '[*] Info is saved into %s'%(output)