-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
127 lines (106 loc) · 2.88 KB
/
main.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
import urllib.request
import json
import webtech
from wplzer import Wappalyzer, WebPage
import hashlib
import csv
def makedict(url): #辞書型配列を作成
arr=[]
arr.extend(get_serverheader(url))
arr.extend(get_tech(url))
arr.extend(get_wappalyzer(url))
#arr.extend(get_etag(url))
dic={}
print(arr)
for i in arr:
if i[0] not in dic and len(i)==2:
dic[i[0]]=i[1]
elif dic[i[0]]==None:
dic[i[0]]=i[1]
#print(dic)
#csvに保存するコードを書く
#見やすいように自分で変更を行う
#print(dic.keys())
#print(dic.values())
filename = url.replace('/', '').replace('.', '').replace(':', '')
version = ""
if 'WordPress' in dic:
version = dic["WordPress"]
if version==None:
version="no version"
else:
version = "None"
print(url + ",version :"+ version)
with open('output.csv', 'a') as f:
print(url + ","+ version, file=f)
'''
with open(filename, 'w') as f:
writer = csv.writer(f)
writer.writerow(dic.keys())
writer.writerow(dic.values())
'''
def get_wappalyzer(url):
wappalyzer = Wappalyzer.latest()
webpage = WebPage.new_from_url(url)
datas=[]
parsed=wappalyzer.analyze_with_versions(webpage).values()
for i in parsed:
datas.append(list(i.values()))
if datas[-1][-1]!=None:
datas[-1][-1]=datas[-1][-1][0]
return datas
def get_serverheader(url):
try:
with urllib.request.urlopen(url) as response:
headers = response.getheaders()
status = response.getcode()
datas=[]
#datas.append(url)
for i in headers:
if i[0]=="Server" or i[0]=="X-Powered-By":
for j in i[1].split(" "):
datas.append(j.replace("(","").replace(")","").split("/"))
#datas.extend(i[1].split(" "))
for i in range(len(datas)):
if len(datas[i])!=2:
datas[i].append(None)
return datas
except urllib.error.URLError as e:
return e.reason
def get_tech(url):
wt = webtech.WebTech(options={'json': True})
try:
report = wt.start_from_url(url)
data=[]
#data.append(url)
for i in report["tech"]:
data.append(list(i.values()))
return data
except webtech.utils.ConnectionException:
return "Connection error"
def get_etag(url):
try:
with urllib.request.urlopen(url) as response:
headers = response.getheaders()
for i in headers:
if i[0]=="ETag":
return i[1]
body = response.read()
hs = hashlib.md5(body.decode('utf-8').encode()).hexdigest()
return [["etag",hs]]
except urllib.error.URLError as e:
return e.reason
def page2md5(url):
try:
with urllib.request.urlopen(url) as response:
body = response.read()
hs = hashlib.md5(body.decode('utf-8').encode()).hexdigest()
return hs
except urllib.error.URLError as e:
return e.reason
if __name__ == '__main__':
#url = 'https://www.kinkiyoken.co.jp/'
#url = 'https://cysec.ise.ritsumei.ac.jp/'
#url = "http://www.rcc.ritsumei.ac.jp/"
print("url:"+url)
makedict(url)