/// <summary> /// Gets a string which represents a unique signature of this machine based on MAC addresses of interfaces. /// The signature has a form of: [intf.count]-[CRC32 of all MACs]-[convoluted MD5 of all MACs] /// </summary> public static string GetMachineUniqueMACSignature() { var nics = NetworkInterface.GetAllNetworkInterfaces(); var buf = new byte[6 * 32]; var ibuf = 0; var cnt=0; var csum = new NFX.IO.ErrorHandling.CRC32(); foreach(var nic in nics.Where(a => a.NetworkInterfaceType!=NetworkInterfaceType.Loopback)) { var mac = nic.GetPhysicalAddress().GetAddressBytes(); csum.Add( mac ); for(var i=0; i<mac.Length; i++) { buf[ibuf] = mac[i]; ibuf++; if(ibuf==buf.Length) ibuf = 0; } cnt++; } var md5s = new StringBuilder(); using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider()) { var hash = md5.ComputeHash(buf); for(var i=0 ; i<hash.Length ; i+=2) md5s.Append( (hash[i]^hash[i+1]).ToString("X2")); } return "{0}-{1}-{2}".Args( cnt, csum.Value.ToString("X8"), md5s ); }
/// <summary> /// Gets a string which represents a unique signature of this machine based on MAC addresses of interfaces. /// The signature has a form of: [intf.count]-[CRC32 of all MACs]-[convoluted MD5 of all MACs] /// </summary> public static string GetMachineUniqueMACSignature() { var nics = NetworkInterface.GetAllNetworkInterfaces(); var buf = new byte[6 * 32]; var ibuf = 0; var cnt = 0; var csum = new NFX.IO.ErrorHandling.CRC32(); foreach (var nic in nics.Where(a => a.NetworkInterfaceType != NetworkInterfaceType.Loopback)) { var mac = nic.GetPhysicalAddress().GetAddressBytes(); csum.Add(mac); for (var i = 0; i < mac.Length; i++) { buf[ibuf] = mac[i]; ibuf++; if (ibuf == buf.Length) { ibuf = 0; } } cnt++; } var md5s = new StringBuilder(); using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider()) { var hash = md5.ComputeHash(buf); for (var i = 0; i < hash.Length; i += 2) { md5s.Append((hash[i] ^ hash[i + 1]).ToString("X2")); } } return("{0}-{1}-{2}".Args(cnt, csum.Value.ToString("X8"), md5s)); }