/// <summary> /// Returns a hash value for an ArpEntry /// </summary> /// <returns></returns> public override int GetHashCode() { return(IPAddress.GetHashCode() | PhysicalAddress.GetHashCode() | AdapterIndex.GetHashCode() | ArpEntryType.GetHashCode()); }
public override string ToString() { return($"AdapterIndex={AdapterIndex.ToString()},BusNumber={BusNumber.ToString()},DeviceNumber={DeviceNumber.ToString()},AdapterName={AdapterName}"); }
public bool ConfigStaticAddress(Logger logger, string newAddress, string newSubnet, string newGateway) { try { var configQuery = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " + AdapterIndex.ToString()); foreach (ManagementObject configResult in configQuery.Get()) { var EnableStaticAddrMethod = configResult.GetMethodParameters("EnableStatic"); EnableStaticAddrMethod["IPAddress"] = new string[] { newAddress }; EnableStaticAddrMethod["SubnetMask"] = new string[] { newSubnet }; var SetGatewayMethod = configResult.GetMethodParameters("SetGateways"); SetGatewayMethod["DefaultIPGateway"] = new string[] { newGateway }; SetGatewayMethod["GatewayCostMetric"] = new int[] { 1 }; configResult.InvokeMethod("EnableStatic", EnableStaticAddrMethod, null); configResult.InvokeMethod("SetGateways", SetGatewayMethod, null); } return(true); } catch (Exception e) { logger.Log(e, $"Failed to configure adapter [{ AdapterName }] for static IP address."); return(false); } }