Minor fixes and Mac > 2 check
This commit is contained in:
parent
1de5848edb
commit
83c82f799f
3 changed files with 24 additions and 16 deletions
|
@ -44,13 +44,13 @@ namespace SafeExamBrowser.SystemComponents.Contracts
|
|||
string OperatingSystemInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The MAC Addres of the network addapter
|
||||
/// The MAC address of the network adapter
|
||||
/// </summary>
|
||||
string MacAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides the DeviceID information of the user's Plug and Play devices
|
||||
/// </summary>
|
||||
string[] DeviceId { get; }
|
||||
string[] PlugAndPlayDeviceIds { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace SafeExamBrowser.SystemComponents
|
|||
public string Name { get; private set; }
|
||||
public OperatingSystem OperatingSystem { get; private set; }
|
||||
public string MacAddress { get; private set; }
|
||||
public string[] DeviceId { get; private set; }
|
||||
public string[] PlugAndPlayDeviceIds { get; private set; }
|
||||
|
||||
public string OperatingSystemInfo
|
||||
{
|
||||
|
@ -133,16 +133,18 @@ 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)
|
||||
|
||||
if (results != null && results.Count > 0)
|
||||
{
|
||||
using (var system = results.Cast<ManagementObject>().First())
|
||||
using (var networkAdapter = results.Cast<ManagementObject>().First())
|
||||
{
|
||||
foreach (var property in system.Properties)
|
||||
foreach (var property in networkAdapter.Properties)
|
||||
{
|
||||
|
||||
if (property.Name.Equals("MACAddress"))
|
||||
|
@ -158,25 +160,27 @@ namespace SafeExamBrowser.SystemComponents
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializePnPDevices()
|
||||
{
|
||||
List<string> deviceList = new List<string>();
|
||||
var deviceList = new List<string>();
|
||||
using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT DeviceID FROM Win32_PnPEntity"))
|
||||
using (var results = searcher.Get())
|
||||
{
|
||||
foreach (ManagementObject queryObj in results)
|
||||
{
|
||||
using (queryObj)
|
||||
using (queryObj)
|
||||
{
|
||||
foreach (var property in queryObj.Properties)
|
||||
{
|
||||
if (property.Name.Equals("DeviceID"))
|
||||
{
|
||||
Console.WriteLine(Convert.ToString(property.Value));
|
||||
deviceList.Add(Convert.ToString(property.Value).ToLower());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DeviceId = deviceList.ToArray();
|
||||
PlugAndPlayDeviceIds = deviceList.ToArray();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,21 +32,25 @@ namespace SafeExamBrowser.SystemComponents
|
|||
var manufacturer = systemInfo.Manufacturer.ToLower();
|
||||
var model = systemInfo.Model.ToLower();
|
||||
var macAddress = systemInfo.MacAddress;
|
||||
var deviceId = systemInfo.DeviceId;
|
||||
|
||||
var plugAndPlayDeviceIds = systemInfo.PlugAndPlayDeviceIds;
|
||||
|
||||
isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface");
|
||||
isVirtualMachine |= manufacturer.Contains("vmware");
|
||||
isVirtualMachine |= manufacturer.Contains("parallels software");
|
||||
isVirtualMachine |= model.Contains("virtualbox");
|
||||
isVirtualMachine |= manufacturer.Contains("qemu");
|
||||
|
||||
isVirtualMachine |= ((byte.Parse(macAddress[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddress.StartsWith("080027"));
|
||||
|
||||
foreach (var device in deviceId)
|
||||
|
||||
if (macAddress != null && macAddress.Count() > 2)
|
||||
{
|
||||
isVirtualMachine |= ((byte.Parse(macAddress[1].ToString(), NumberStyles.HexNumber) & 2) == 2 || macAddress.StartsWith("080027"));
|
||||
}
|
||||
|
||||
foreach (var device in plugAndPlayDeviceIds)
|
||||
{
|
||||
isVirtualMachine |= PCI_VENDOR_BLACKLIST.Any(device.ToLower().Contains);
|
||||
|
||||
}
|
||||
|
||||
logger.Debug($"Computer '{systemInfo.Name}' appears to {(isVirtualMachine ? "" : "not ")}be a virtual machine.");
|
||||
|
||||
return isVirtualMachine;
|
||||
|
|
Loading…
Add table
Reference in a new issue