พัฒนา web application ด้วย Java

javascript check mac address with key

 const os = require('os');

const crypto = require('crypto');function getHashedMacAddress(secretKey) { const networkInterfaces = os.networkInterfaces(); let macAddress = null; // Iterate over network interfaces to find a valid MAC address for (const interfaceName in networkInterfaces) { for (const networkInterface of networkInterfaces[interfaceName]) { // Exclude loopback interfaces and ensure it's not an internal address if (!networkInterface.internal && networkInterface.mac !== '00:00:00:00:00:00') { macAddress = networkInterface.mac; break; // Found a MAC address, exit inner loop } } if (macAddress) { break; // Found a MAC address, exit outer loop } } if (!macAddress) { throw new Error('Could not find a valid MAC address on this machine.'); } // Create an HMAC hash with the provided secret key const hmac = crypto.createHmac('sha256', secretKey); hmac.update(macAddress); return hmac.digest('hex');}// Example usage:const SECRET_KEY = 'your_super_secret_key'; // Replace with a strong, unique keyconst EXPECTED_HASHED_MAC = 'your_precomputed_hashed_mac_constant'; // Replace with your constanttry { const currentHashedMac = getHashedMacAddress(SECRET_KEY); if (currentHashedMac === EXPECTED_HASHED_MAC) { console.log('MAC address matches the expected constant.'); } else { console.log('MAC address does NOT match the expected constant.'); console.log('Current Hashed MAC:', currentHashedMac); }} catch (error) { console.error('Error:', error.message);}
javascript check mac address with key javascript check mac address with key Reviewed by Mr.Boonchai on ธันวาคม 04, 2568 Rating: 5

ไม่มีความคิดเห็น:

Thank you

ขับเคลื่อนโดย Blogger.