-
Notifications
You must be signed in to change notification settings - Fork 15
/
get_host_from_url.py
51 lines (42 loc) · 1.32 KB
/
get_host_from_url.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
#! /usr/bin/env python
# -*- coding:utf-8 -*-
# author:flystart
# home:www.flystart.org
# time:2020/2/21
import optparse
import sys
import urlparse
def put_file_contents(filename,contents):
with open(filename,"ab+") as fin:
fin.write(contents+"\n")
def get_file_content(filename):
result = []
f = open(filename, "r")
for line in f.readlines():
result.append(line.strip())
f.close()
return result
def url2host(url):
parts = urlparse.urlparse(url)
host = parts.netloc
return host
def main():
commandList = optparse.OptionParser('usage: %prog [-f store hosts file ]')
commandList.add_option('-f', '--file', action='store',
help='Insert filename of stored hosts ::')
commandList.add_option('-u', '--url', action="store",
help="Insert TARGET URL: http[s]://www.victim.com[:PORT]",
)
options, remainder = commandList.parse_args()
if (not options.file) and (not options.url):
commandList.print_help()
sys.exit(1)
urls = [options.url] if options.url else get_file_content(options.file)
for url in urls:
host = url2host(url)
if ":" in host:
host = host.split(":")[0]
print(host)
put_file_contents("parse_hosts.txt",host)
if __name__ == "__main__":
main()