Changeset 12247 for branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Clients.Hive.Slave/3.3
- Timestamp:
- 03/24/15 11:17:08 (10 years ago)
- Location:
- branches/HeuristicLab.DatasetRefactor/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatasetRefactor/sources
- Property svn:mergeinfo changed
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs
r12031 r12247 25 25 using System.Linq; 26 26 using System.Management; 27 using System.Net.NetworkInformation; 27 28 using HeuristicLab.Clients.Hive.SlaveCore.Properties; 28 29 … … 34 35 public class ConfigManager { 35 36 private static ConfigManager instance = null; 37 private const string vmwareNameString = "VMware"; 38 private const string virtualboxNameString = "VirtualBox"; 39 private const int macLength = 12; 40 36 41 public static ConfigManager Instance { 37 42 get { return instance; } … … 179 184 /// </summary> 180 185 private static Guid GetUniqueMachineIdFromMac() { 181 ManagementClass mgtClass = new ManagementClass("Win32_NetworkAdapterConfiguration"); 182 ManagementObjectCollection mgtCol = mgtClass.GetInstances(); 183 184 foreach (ManagementObject mgtObj in mgtCol) { 185 foreach (var prop in mgtObj.Properties) { 186 if (prop.Value != null && prop.Name == "MACAddress") { 187 try { 188 //simply take the first nic 189 string mac = prop.Value.ToString(); 190 byte[] b = new byte[8]; 191 string[] macParts = mac.Split(':'); 192 if (macParts.Length == 6) { 193 for (int i = 0; i < macParts.Length; i++) { 194 b[i + 2] = (byte)((ParseNybble(macParts[i][0]) << 4) | ParseNybble(macParts[i][1])); 195 } 196 197 // also get machine name and save it to the first 4 bytes 198 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, b); 199 return guid; 200 } else 201 throw new Exception("Error getting mac addresse"); 202 } 203 catch { 204 throw new Exception("Error getting mac addresse"); 205 } 206 } 207 } 208 } 209 throw new Exception("Error getting mac addresse"); 186 //try to get a real network interface, not a virtual one 187 NetworkInterface validNic = NetworkInterface.GetAllNetworkInterfaces() 188 .FirstOrDefault(x => 189 !x.Name.Contains(vmwareNameString) && 190 !x.Name.Contains(virtualboxNameString) && 191 (x.NetworkInterfaceType == NetworkInterfaceType.Ethernet || 192 x.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet)); 193 194 if (validNic == default(NetworkInterface)) { 195 validNic = NetworkInterface.GetAllNetworkInterfaces().First(); 196 } 197 198 string addr = validNic.GetPhysicalAddress().ToString(); 199 if (addr.Length != macLength) { 200 throw new Exception("Error generating slave UID: MAC address has to have " + macLength + " digits. Actual MAC address is: " + addr); 201 } 202 203 byte[] b = new byte[8]; 204 int j = 2; 205 for (int i = 0; i < macLength; i += 2) { 206 b[j++] = (byte)((ParseNybble(addr[i]) << 4) | ParseNybble(addr[i + 1])); 207 } 208 // also get machine name and save it to the first 4 bytes 209 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, b); 210 return guid; 210 211 } 211 212
Note: See TracChangeset
for help on using the changeset viewer.