-
Notifications
You must be signed in to change notification settings - Fork 41
/
update_assets.py
119 lines (94 loc) · 3.44 KB
/
update_assets.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
import argparse
import sys
import requests
# Script for updating the v20 and v21 assets from IANA website.
def v20_get_media_types(odir):
categories = [
'application',
'audio',
'font',
'image',
'message',
'model',
'multipart',
'text',
'video'
]
for cat in categories:
fn = '%s.csv' % cat
url = 'http://www.iana.org/assignments/media-types/%s' % fn
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v20/assets/mediatype_%s' % fn, mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v20_get_charsets(odir):
data = requests.get('http://www.iana.org/assignments/character-sets/character-sets-1.csv')
data.raise_for_status()
with open(odir + '/v20/assets/charsets.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v20_get_protocols(odir):
url = 'http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv'
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v20/assets/protocols.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v20_get_ipfix(odir):
url = 'http://www.iana.org/assignments/ipfix/ipfix-information-elements.csv'
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v20/assets/ipfix-information-elements.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v21_get_media_types(odir):
categories = [
'application',
'audio',
'font',
'image',
'message',
'model',
'multipart',
'text',
'video'
]
for cat in categories:
fn = '%s.csv' % cat
url = 'http://www.iana.org/assignments/media-types/%s' % fn
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v21/assets/mediatype_%s' % fn, mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v21_get_charsets(odir):
data = requests.get('http://www.iana.org/assignments/character-sets/character-sets-1.csv')
data.raise_for_status()
with open(odir + '/v21/assets/charsets.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v21_get_protocols(odir):
url = 'http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv'
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v21/assets/protocols.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def v21_get_ipfix(odir):
url = 'http://www.iana.org/assignments/ipfix/ipfix-information-elements.csv'
data = requests.get(url)
data.raise_for_status()
with open(odir + '/v21/assets/ipfix-information-elements.csv', mode='wb') as fd:
fd.write(data.text.encode('utf-8'))
def main(argv):
pars = getArgParser()
opts = pars.parse_args(argv)
v20_get_media_types(opts.odir)
v20_get_charsets(opts.odir)
v20_get_protocols(opts.odir)
v20_get_ipfix(opts.odir)
v21_get_media_types(opts.odir)
v21_get_charsets(opts.odir)
v21_get_protocols(opts.odir)
v21_get_ipfix(opts.odir)
def getArgParser():
pars = argparse.ArgumentParser(prog='update_assets')
pars.add_argument('-o', '--output', dest='odir', default='./stix2validator/', type=str,
help='Package directory.')
return pars
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))