diff --git a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs
index 18eeb45c..9b6d9742 100644
--- a/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs
+++ b/SafeExamBrowser.SystemComponents.Contracts/ISystemInfo.cs
@@ -42,5 +42,10 @@ namespace SafeExamBrowser.SystemComponents.Contracts
/// Provides detailed version information about the currently running operating system.
///
string OperatingSystemInfo { get; }
+
+ ///
+ /// The MAC Addres of the network addapter
+ ///
+ string MacAddress { get; }
}
}
diff --git a/SafeExamBrowser.SystemComponents/SystemInfo.cs b/SafeExamBrowser.SystemComponents/SystemInfo.cs
index e0655682..570dd6ef 100644
--- a/SafeExamBrowser.SystemComponents/SystemInfo.cs
+++ b/SafeExamBrowser.SystemComponents/SystemInfo.cs
@@ -23,6 +23,7 @@ namespace SafeExamBrowser.SystemComponents
public string Model { get; private set; }
public string Name { get; private set; }
public OperatingSystem OperatingSystem { get; private set; }
+ public string MacAddress { get; private set; }
public string OperatingSystemInfo
{
@@ -34,6 +35,7 @@ namespace SafeExamBrowser.SystemComponents
InitializeBattery();
InitializeMachineInfo();
InitializeOperatingSystem();
+ InitializeMacAddress();
}
private void InitializeBattery()
@@ -128,5 +130,30 @@ namespace SafeExamBrowser.SystemComponents
{
return Environment.Is64BitOperatingSystem ? "x64" : "x86";
}
+ private void InitializeMacAddress()
+ {
+ using (var searcher = new ManagementObjectSearcher("Select MACAddress from Win32_NetworkAdapterConfiguration WHERE DNSDomain IS NOT NULL"))
+ using (var results = searcher.Get())
+ {
+ if (results.Count > 0)
+ {
+ using (var system = results.Cast().First())
+ {
+ foreach (var property in system.Properties)
+ {
+
+ if (property.Name.Equals("MACAddress"))
+ {
+ MacAddress = Convert.ToString(property.Value).Replace(":", "").ToUpper();
+ }
+ }
+ }
+ }
+ else
+ {
+ MacAddress = "000000000000";
+ }
+ }
+ }
}
}
diff --git a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs
index 52855d7b..df4b24a6 100644
--- a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs
+++ b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs
@@ -9,17 +9,17 @@
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.SystemComponents.Contracts;
using System.Globalization;
-using System.Linq;
-using System.Management;
-using System.Net.NetworkInformation;
+
namespace SafeExamBrowser.SystemComponents
{
public class VirtualMachineDetector : IVirtualMachineDetector
{
+ private static readonly string[] PCI_VENDOR_BLACKLIST = { "vbox", "80ee", "qemu", "1af4", "1b36" }; //Virtualbox: VBOX, 80EE RedHat: QUEMU, 1AF4, 1B36
+
private ILogger logger;
private ISystemInfo systemInfo;
- private static readonly string[] pciVendorBlacklist = { "vbox", "80ee", "qemu", "1af4", "1b36" }; //Virtualbox: VBOX, 80EE RedHat: QUEMU, 1AF4, 1B36
+
public VirtualMachineDetector(ILogger logger, ISystemInfo systemInfo)
{
this.logger = logger;
@@ -31,6 +31,7 @@ namespace SafeExamBrowser.SystemComponents
var isVirtualMachine = false;
var manufacturer = systemInfo.Manufacturer.ToLower();
var model = systemInfo.Model.ToLower();
+ var macAddress = systemInfo.MacAddress;
isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface");
isVirtualMachine |= manufacturer.Contains("vmware");
@@ -38,9 +39,8 @@ namespace SafeExamBrowser.SystemComponents
isVirtualMachine |= model.Contains("virtualbox");
isVirtualMachine |= manufacturer.Contains("qemu");
- var macAddr = (from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();
- isVirtualMachine |= ((byte.Parse(macAddr[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddr.StartsWith("080027"));
-
+ isVirtualMachine |= ((byte.Parse(macAddress[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddress.StartsWith("080027"));
+ /*
using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT DeviceID FROM Win32_PnPEntity"))
foreach (ManagementObject queryObj in searcher.Get())
@@ -48,7 +48,7 @@ namespace SafeExamBrowser.SystemComponents
isVirtualMachine |= pciVendorBlacklist.Any(System.Convert.ToString(queryObj.Properties.Cast().First().Value).ToLower().Contains);
}
-
+ */
logger.Debug($"Computer '{systemInfo.Name}' appears to {(isVirtualMachine ? "" : "not ")}be a virtual machine.");
return isVirtualMachine;