-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrnhost.py
162 lines (140 loc) · 4.63 KB
/
srnhost.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#-*- coding:utf-8 -*-
#####Sirin Domain Address Searcher by MisakaSirin#####
#WARN:该文件内容已经作废,仅作为早期开发与测试文件,可删除
import urllib.request
import urllib.error
from bs4 import BeautifulSoup as bs
import sys
import re
import os
import getopt
print('Sirin Domain Address Searcher ver. 1.0.2 Build4F3CE2D')
ipv4s = []
ipv6s = []
l = []
usage = '''
Sirin Domain Address Searcher ver 1.0.2 Build4F3CE2D Developed by MisakaSirin
Usage: srndas <Target Domain Name>/[-h]/[-b]/[-r] [-w [FILENAME]]/[-e]/[-l]
Target Domain Name: The domain name that you want to search(this shoud be the first arg)
-h --help: Show this page
-b --backup: Make a backup file for /etc/hosts before other progress
-r --restore Restore /etc/hosts from a file (Normally ~/.SirinDAS)
-w --write Write result to a certain file (Normally /etc/hosts, this operation requires root permission)
-l --load Force system to load /etc/hosts when the previous progress is done
Example: srndas www.sirin.net.cn -w ~/example.txt
HAVE FUN :)
'''
#后续加入功能,不完善
'''
def aligns(string, length=20):
difference = length - len(string) # 计算限定长度为20时需要补齐多少个空格
if difference == 0: # 若差值为0则不需要补
return string
elif difference < 0:
print('[!] Error! IntE_6_Tab')
sys.exit(10)
new_string = ''
space = ' '
for i in string:
#print("Current: " + str(i))
#codes = ord(i) # 将字符转为ASCII或UNICODE编码
#if codes <= 126: # 若是半角字符
#new_string = new_string + chr(codes+65248) # 则转为全角
#else:
new_string = new_string + i # 若是全角,则不转换
return new_string + space*(difference) # 返回补齐空格后的字符串
def tabulator(inputlist, column, length=20):
p = ''
num = 0
sum = len(inputlist)
for i in inputlist:
p = p + aligns(i,length)
num = num + 1
sum = sum - 1
if num >= column:
print(p)
p = ''
num = 0
elif sum <= 0:
print(p)
'''
if os.geteuid() != 0:
print("[!] Aborting. (No Permission)")
sys.exit(2)
if len(sys.argv) == 0:
print('[!] Aborting. (No Args)')
sys.exit(15)
input = sys.argv[1]
print('[*] Getting Page: ' + input + ' --> ' + site)
site = 'https://' + site
try:
#headers = {'User_Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0'}
headers = {'User_Agent': "MisakaSirin bot"}
response = urllib.request.Request(site, headers=headers)
html = urllib.request.urlopen(response)
result = html.read().decode('utf-8')
except urllib.error.URLError as e:
if hasattr(e, 'reason'):
print('[-] Aborting. ' + str(e.reason))
sys.exit(10086)
except urllib.error.HTTPError as e:
if hasattr(e, 'code'):
print('[-] Aborting. ERR' + str(e.code))
sys.exit(int(e.code))
else:
print('[+] Page Get')
print('[*] Analyzing Page')
soup = bs(result, features="lxml")
ipv4 = soup.find_all("a", href=re.compile("https://www.ipaddress.com/ipv4/"))
#print(ipv4)
ipv6 = soup.find_all("a", href=re.compile("https://www.ipaddress.com/ipv6/"))
ipv6 = list(set(ipv6))
#print(ipv6)
for i in range(0, len(ipv4)):
t = str(ipv4[i])
stpce = t.find('>') + 1
edpce = t.find('<', stpce) - 1
ipv4s.append(t[stpce:edpce])
for i in range(0, len(ipv6)):
t = str(ipv6[i])
stpce = t.find('>') + 1
edpce = t.find('<', stpce) - 1
ipv6s.append(t[stpce:edpce])
ipv6s = list(set(ipv6s)) #去除重复项
ipv4s = list(set(ipv4s)) #去除重复项
print('[+] Result:')
print(' Find ' + str(len(ipv4s)) + ' IPv4', end = '')
print(', ' + str(len(ipv6s)) + ' IPv6' , end = '')
print('for ' + input)
print(' No. IP Address | Domain Name')
print(' ---------------------------------------------')
if len(ipv4) == 0:
print(' [===No IPv4 Found]===')
else:
#TabAuto
'''
for i in range(0, len(ipv4)):
l.append(str(i))
l.append(ipv4s[i])
l.append(input)
#print(l)
tabulator(l, 3, 10)
'''
for i in range(0, len(ipv4s)):
print(" ", 4*10 + i, " ", ipv4s[i], " ", input)
print()
if len(ipv6) == 0:
print(' [===No IPv6 Found===]')
if len(ipv4s) == 0:
print('[!] No IP found. Exiting.')
else:
for i in range(0, len(ipv6s)):
print(" ", 6*10 + i, " ", ipv6s[i], " ", input)
'''
r = input('[?] Write to hosts file? (y/n)')
if r == 'y' or r == 'Y':
pass
else:
print('[-] Aborting.(Operate by User)')
sys.exit(0)
'''