/// <summary> /// Getting Hardware Master information against IP address /// </summary> /// <param name="Tempaddr"></param> /// <returns></returns> public static string[] GetHwMasterInfo(System.Net.IPHostEntry Tempaddr) { string[] Ipaddr = new string[2]; try { System.Net.IPAddress[] TempAd = Tempaddr.AddressList; foreach (IPAddress TempA in TempAd) { Ipaddr[0] = TempA.ToString(); byte[] ab = new byte[6]; int len = ab.Length; // This Function Used to Get The Physical Address int r = SendARP((int)TempA.Address, 0, ab, ref len); string mac = BitConverter.ToString(ab, 0, 6); Ipaddr[1] = mac; } } catch (Exception ex) { WriteTextFile.WriteErrorLog("Hardware Master Information ERROR:"); WriteTextFile.WriteErrorLog("=========================================="); WriteTextFile.WriteErrorLog(ex); } return(Ipaddr); }
private void ProcessMachine(DirectoryEntry machine, List <MachineEntity> computerNames) { MachineEntity machineEntity = new MachineEntity(); string[] Ipaddr = new string[3]; System.Net.IPHostEntry Tempaddr = null; byte[] ab; int len; int r; string mac = string.Empty; Ipaddr[0] = machine.Name; try { Tempaddr = (System.Net.IPHostEntry)Dns.GetHostEntry(machine.Name); } catch (Exception) { return; } foreach (IPAddress TempA in Tempaddr.AddressList) { Ipaddr[1] = TempA.ToString(); ab = new byte[6]; len = ab.Length; r = SendARP(TempA.GetHashCode(), 0, ab, ref len); mac = BitConverter.ToString(ab, 0, 6); if (mac == "00-00-00-00-00-00") { return; } Ipaddr[2] = mac; } machineEntity.MachineStatus = MachineStatus.Online; machineEntity.IPAddress = Ipaddr[1]; machineEntity.MachineName = machine.Name; machineEntity.MachineMACAddress = Ipaddr[2]; computerNames.Add(machineEntity); }