-
Notifications
You must be signed in to change notification settings - Fork 13
/
ua2os.py
executable file
·136 lines (127 loc) · 5.25 KB
/
ua2os.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
"""ua to os - from a user agent return operating system, architecture, and browser"""
import sys,splunk.Intersplunk
import re
os_mapping = (
('Windows .. 5.1', 'Windows XP'),
('Windows .. 5.2', 'Windows XP'),
('Windows NT 6.0', 'Windows Vista'),
('Windows 6.0', 'Windows Server 2008'),
('Windows NT 6.1', 'Windows 7'),
('Windows NT 6.2', 'Windows 8'),
('Windows NT 6.3', 'Windows 8.1'),
('Windows NT 10.0', 'Windows 10'),
('OS X 10.(\d)', 'Mac OS X 10.%s.x'),
('SunOS', 'Solaris'),
('droid', 'Android'),
('Windows', 'Windows - Other'),
('iPad[^d]', 'iPad'),
('iPod', 'iPod'),
('iPhone', 'iPhone'),
('OS X', 'Mac OS X - Other'),
('Darwin', 'Mac OS X - Other'),
('Linux ', 'Linux'),
('winhttp', 'Windows - Other'),
('MSIE 4.0;', 'Windows - Other'),
('Microsoft', 'Windows - Other'),
('Win32', 'Windows - Other'),
('BlackBerry', 'BlackBerry'),
('BB10', 'BlackBerry 10'),
('RIM (\S+ \S+ \S+)', 'BlackBerry %s'),
('OS/2', 'OS/2'),
('urlgrabber/.* yum', 'Linux - RedHat/Fedora'),
('Skype for Macintosh', 'Mac OS X - Other'),
('Xbox Live Client', 'Xbox'),
('hpwOS/(\S+)', 'HP webOS %s'),
('J2ME', 'JVM Micro Edition'),
('CrOS', 'Chromium OS'),
('FreeBSD', 'FreeBSD'),
)
browser_mapping = (
('MSIE 7.*Trident/4.0', 'Internet Explorer 8.0'),
('MSIE ([9876]).0', 'Internet Explorer %s.0'),
('MSIE 10.0', 'Internet Explorer 10.0'),
('Trident/7.0; (?:Touch; )?rv:11.0','Internet Explorer 11.0'),
('droid', 'Android'),
('Chrome', 'Chrome'),
('Mobile.*Safari', 'Safari - mobile'),
('i(pod|pad|phone).*(Safari|AppleWebKit)', 'Safari - mobile'),
('Safari/', 'Safari'),
('iTunes', 'iTunes'),
('Firefox/(\d+)', 'Firefox %s'),
('MSIE 5.00', 'Internet Explorer 5.0'),
('MSIE', 'Internet Explorer - Other'),
('AppleWebKit', 'Safari'),
('Google Update', 'Google Update'),
('Opera Mini', 'Opera Mini'),
('Opera', 'Opera'),
('urlgrabber/.* yum', 'yum'),
('BlackBerry', 'Blackberry'),
('Googlebot', 'Googlebot'),
('Baiduspider', 'Baidubot'),
('NING/\d', 'Ning'),
('msnbot/\d', 'msnbot'),
('gsa-crawler', 'Google Search Appliance'),
('Ezooms/\d', 'Ezooms'),
('bingbot', 'bingbot'),
('YandexBot', 'yandexbot'),
('Genieo', 'genieo'),
('Apple-PubSub', 'Apple PubSub'),
('Java/\d', 'Java'),
('Warp (\S+)', 'Warp %s'),
('wOSBrowser/(\S+)', 'webOS Browser %s'),
('SeaMonkey/(\S+)', 'SeaMonkey %s'),
)
arch_mapping = (
('Windows .. 5.2', 'x64'),
('x64', 'x64'),
('Win64', 'x64'),
('Windows .. 6.1.*WOW64', 'x64'),
('Windows .. 6.([012])\; Trident/', 'i386'),
('i386', 'i386'),
('i686', 'i686'),
('x86_64', 'x64'),
('amd64', 'x64'),
('PPC', 'PowerPC'),
('Power.{1,3}Macint', 'PowerPC'),
('droid', 'Android'),
('iPad[^d]', 'iPad'),
('iPod', 'iPod'),
('iPhone', 'iPhone'),
('Intel', 'Intel'),
('BlackBerry (\d+)', 'BlackBerry %s'),
('BlackBerry', 'BlackBerry'),
('BB10', 'BlackBerry 10'),
('Playbook', 'BlackBerry Playbook'),
('hp-tablet', 'HP Tablet'),
('armv(\d+)', 'ARM v%s'),
)
os_mapping = [(re.compile(a, re.IGNORECASE),b) for (a,b) in os_mapping]
browser_mapping = [(re.compile(a, re.IGNORECASE),b) for (a,b) in browser_mapping]
arch_mapping = [(re.compile(a, re.IGNORECASE),b) for (a,b) in arch_mapping]
def get_thing(line, mapping):
for r, name in mapping:
match = r.search(line)
if match:
if '%' in name:
return name % match.groups()
else:
return name
return 'unknown'
def get_ua_info(line):
i = {}
i['operating_system'] = get_thing(line, os_mapping)
i['architecture'] = get_thing(line, arch_mapping)
i['browser'] = get_thing(line, browser_mapping)
return i
try:
results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
for r in results:
if "_raw" not in r:
continue
info = get_ua_info(r['_raw'])
r.update(info)
except:
import traceback
stack = traceback.format_exc()
results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))
splunk.Intersplunk.outputResults( results )