前端设备指纹

本文介绍如何使用fingerprintjs2库生成前端设备指纹。通过设置选项排除特定特征,并自定义获取操作系统版本的功能,最终生成设备指纹并展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前端设备指纹的生成,可使用fingerprintjs2

github地址: https://github.com/Valve/fingerprintjs2

 

demo:

// 初始化(options: 可设置需要忽略掉的特征属性, callback: 回调方法)
new Fingerprint2({excludeHasLiedBrowser: true, excludeIndexedDB: true,excludeUserAgent: true, excludeJsFonts: true, customFunction: function(){
    // 获取浏览器所在机器操作系统版本
    var u = navigator.userAgent,version = '';
    if (u.indexOf('Mac OS X') > -1) {
        //ios
        var regStr_saf = /OS [\d._]*/gi;
        var verinfo = u.match(regStr_saf);
        version = (verinfo + "").replace(/[^0-9|_.]/ig,'').replace(/_/ig,'.');
    } else if (u.indexOf('Android') > -1
        || u.indexOf('Linux') > -1) {
        //android
        version = u.substr(u.indexOf('Android') + 8, u.indexOf(";", u.indexOf("Android")) - u.indexOf('Android') - 8);
    } else if (u.indexOf('BB10') > -1) {
        //黑莓bb10系统
        version = u.substr(u.indexOf('BB10') + 5, u.indexOf(";", u.indexOf("BB10")) - u.indexOf('BB10') - 5);
    } else if (u.indexOf('IEMobile')) {
        //windows phone
        version = u.substr(u.indexOf('IEMobile') + 9, u.indexOf(";", u.indexOf("IEMobile")) - u.indexOf('IEMobile') - 9);
    }
    return version;
  }}).get(function(result, components){
    console.log(result); //a hash, representing your device fingerprint
    console.log(components); // an array of FP components
    document.getElementById('ua').innerHTML = '<p>hash:</p><p>'+ result +'</p>'
  });

 

转载于:https://www.cnblogs.com/mjian/p/9250093.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值