MAC address and browser fingerprint usage and differences

Some time ago, THE MAC address was used in the development to authenticate the login of the device. Later, it was changed to fingerprintjs2. This is the summary and record for the supplement and correction.

The MAC address

  • It is said that there are many methods for obtaining MAC addresses ActiveX, Flash, and applet are used here
  • disadvantages
    • MAC addresses are unique identifiers for network devices in the world, but they can be manually modified, so their use is not reliable.
    • ActiveX works only with Internet Explorer;
    • ActiveX is disabled by default. Users need to manually enable the ActiveX control (in the browser Internet options -> Security -> Custom Level -> Initialize and execute the Script for the ActiveX control not marked as safe execution -> Enable).
    • The browser will pop up a message indicating unsafe Settings.
    • The aggregate is too restrictive;

  • Go straight to the code
Var locator = new ActiveXObject("WbemScripting.SWbemLocator");
    var service = locator.ConnectServer(".");
    var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
    var e = new Enumerator(properties);
    letMacAddressIp = []; // Multiple MAC addresses may be obtainedfor(; ! e.atEnd(); e.moveNext()) { var p = e.item();if(p.MACAddress ! == null) { MacAddressIp.push(p.MACAddress) } }Copy the code

By the way, put the access to the computer configuration code

    function getSysInfo(){
    var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
    var service = locator.ConnectServer("."); Var CPU = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item(); var cpuType=cpu.Name,hostName=cpu.SystemName; Var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory"));
    for(var mem=[],i=0; ! memory.atEnd(); memory.moveNext()) mem[i++]={cap: memory. The item (). Capacity / 1024/1024, speed: the memory. The item (). The speed} / var/system information system = new Enumerator (service. ExecQuery ("SELECT * FROM Win32_ComputerSystem")).item();
    var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024),curUser=system.UserName,cpuCount=system.NumberOfProcessors
    return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem}
}
Copy the code

Browser Fingerprint Authentication

What is a browser fingerprint?

That is, generate a unique 32-bit code for the browser based on the browser, current system configuration, etc.;

The installation

Online access using CDN:

<script src="https://cdnjs.com/libraries/fingerprintjs2"></script>
Copy the code

Use the bowerinstall command to install:

bower install fingerprintjs2 
Copy the code

Install using the npminstall command:

npm install fingerprintjs2 --save--dev
Copy the code

use

import Fingerprint2 from 'fingerprintjs2'// Use the browser fingerprint var MacAddress; New Fingerprint2({// Optional) excludeSessionStorage:true// Exclude session storage user's browser support for excludeOpenDatabase:true// excludeIndexedDB:true, // excludeLanguage of IndexedDB user browsers:true// Exclude the language of the browser userAgent:true, // User agent, including browser version number}).get(function(result, components){
        MacAddress = result;
    });
Copy the code

Complete list of configuration items

disadvantages

  • There is a chance of duplication;
  • Changing the browser or modifying the system configuration may change the fingerprint code.

The last

Write messy, there is a better way, welcome to add;