forked from gwen001/pentest-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-domains.py
executable file
·50 lines (38 loc) · 1.1 KB
/
extract-domains.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
#!/usr/bin/python2
# I don't believe in license.
# You can do whatever you want with this program.
import os
import sys
import argparse
import tldextract
from urlparse import urlparse
parser = argparse.ArgumentParser()
parser.add_argument( "-u","--urls",help="set urls list (required)" )
parser.add_argument( "-s","--sub",help="subdomains wanted", action="store_true" )
parser.parse_args()
args = parser.parse_args()
if not args.urls:
parser.error( 'urls list is missing' )
if os.path.isfile(args.urls):
fp = open( args.urls, 'r' )
t_urls = fp.read().split("\n")
fp.close()
else:
t_urls = [args.urls]
# print(t_urls)
t_found = []
for url in t_urls:
if not url.startswith( 'http' ):
url = 'https://'+url
t_url_parse = urlparse( url )
# print( t_url_parse )
if args.sub:
found = t_url_parse.netloc
else:
t_host_parse = tldextract.extract( t_url_parse.netloc )
# print( t_host_parse )
found = t_host_parse.domain + '.' + t_host_parse.suffix
if not found in t_found:
t_found.append( found )
print( "\n".join(t_found) )
exit()