public NetInterface(NetworkInterface adapterIn) { // set up the adapter adapter = adapterIn; stats = adapter.GetIPv4Statistics(); // set up the logging logPath = Path.Combine("logs", Path.Combine(adapter.Description, adapter.GetPhysicalAddress().ToString(), adapter.Id)); logHandler = new LogHandler(logPath); loadDataInstant(DateTime.UtcNow.Ticks); // set up the data tracking dataTransferStart = currentTicks(); bytesInSession = stats.BytesReceived; bytesOutSession = stats.BytesSent; properties = adapter.GetIPProperties(); //Console.WriteLine(adapter.Name + " " + adapter.Description + " " + adapter.OperationalStatus); Tracker = new Tracker(logHandler); }
private static IPAddress[] GetAddress(string name, IPInterfaceProperties ipProperties) { if (name == PropertyNames.DefaultGateway) { return(GetIPv4Address(ipProperties.GatewayAddresses.Select(a => a.Address))); } else if (name == PropertyNames.DhcpServer) { return(GetIPv4Address(ipProperties.DhcpServerAddresses.Select(a => a))); } else if (name == PropertyNames.DnsServer) { return(GetIPv4Address(ipProperties.DnsAddresses.Select(a => a))); } else if (name == PropertyNames.IPv4Address) { return(GetIPv4Address(ipProperties.UnicastAddresses.Select(a => a.Address))); } else if (name == PropertyNames.IPv4Subnet) { return(GetIPv4Address(ipProperties.UnicastAddresses.Select(a => a.IPv4Mask))); } else { return new[] { IPAddress.None } }; }
public NetworkDetector() { Logger.V(">> NetworkDetector.NetworkDetector"); m_activeNetwork = null; m_activeIP = null; DetectActiveNetwork(); Logger.V("<< NetworkDetector.NetworkDetector"); }
private static bool HasDNSChanged(IPInterfaceProperties oldProperties, IPInterfaceProperties newProperties) { if (oldProperties.DnsAddresses.Count != newProperties.DnsAddresses.Count) return true; for (int i = 0; i < oldProperties.DnsAddresses.Count; i++) { IPAddress oldDNS = oldProperties.DnsAddresses[i]; IPAddress newDNS = newProperties.DnsAddresses[i]; if (!oldDNS.Equals(newDNS)) return true; } return false; }
private static bool HasDHCPChanged(IPInterfaceProperties oldProperties, IPInterfaceProperties newProperties) { if (oldProperties.GetIPv4Properties().IsDhcpEnabled != newProperties.GetIPv4Properties().IsDhcpEnabled) return true; if (oldProperties.DhcpServerAddresses.Count != newProperties.DhcpServerAddresses.Count) return true; for (int i = 0; i < oldProperties.DhcpServerAddresses.Count; i++) { IPAddress oldDHCP = oldProperties.DhcpServerAddresses[i]; IPAddress newDHCP = newProperties.DhcpServerAddresses[i]; if (!oldDHCP.Equals(newDHCP)) return true; } return false; }
public IPAddress GetMyIPv4Address() { foreach (NetInfo.NetworkInterface netif in NetInfo.NetworkInterface.GetAllNetworkInterfaces()) { //Console.WriteLine("Network Interface: {0}", netif.Name); //System.Console.WriteLine("\tNetworkInterfaceType: {0}", netif.NetworkInterfaceType); #if WINDOWS //System.Console.WriteLine("\tIsReceiveOnly: {0}", netif.IsReceiveOnly); #endif //System.Console.WriteLine("\tOperationalStatus: {0}", netif.OperationalStatus); if (netif.OperationalStatus != NetInfo.OperationalStatus.Up) { continue; } if (netif.NetworkInterfaceType != NetInfo.NetworkInterfaceType.Ethernet && netif.NetworkInterfaceType != NetInfo.NetworkInterfaceType.Wireless80211 ) { continue; } NetInfo.IPInterfaceProperties properties = netif.GetIPProperties(); foreach (NetInfo.IPAddressInformation unicast in properties.UnicastAddresses) { //Console.WriteLine("\tUniCast: {0}", unicast.Address); #if WINDOWS //Console.WriteLine("\t\tIsTransient: {0}", unicast.IsTransient); //Console.WriteLine("\t\tIsDnsEligible: {0}", unicast.IsDnsEligible); #endif if (unicast.Address.AddressFamily == AddressFamily.InterNetwork) { return(unicast.Address); } } } return(IPAddress.Any); throw new Exception("no interface with ip found"); }
protected void Page_Load(object sender, EventArgs e) { System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); System.Net.NetworkInformation.NetworkInterface adapter = nics[0]; System.Net.NetworkInformation.IPInterfaceProperties properties = adapter.GetIPProperties(); Startup_Util.UserMac = adapter.GetPhysicalAddress().ToString(); System.Net.IPHostEntry host; host = System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_HOST"]); Startup_Util.UserPC = host.HostName; Startup_Util.UserIP = Request.ServerVariables["REMOTE_HOST"]; Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache); String ST = Startup_Util.DcryptionPWD(Request.QueryString[0].ToString()); string[] ARY; ARY = ST.Split('~'); string[] ARY1; ARY1 = ARY[0].Split('|'); Startup_Util.SSO_DB = ARY1[9].ToString(); //SINGLE SIGN ON CONNECTION STRING Startup_Util.SPDS_DB = ARY1[10].ToString(); //SPDS CONNECTION STRING Session["EXP_PAGE"] = ARY1[8].ToString(); Session["CompleteInformation"] = ARY1[5].ToString() + " | " + ARY1[6].ToString() + " | "; Label1.Text = Session["CompleteInformation"].ToString(); Session["LOG_CODE"] = ARY1[4].ToString(); Session["U_NAME"] = ARY1[5].ToString(); //I1.Attributes["src"] = "../MasterPage/Default2.aspx"; if (SSO_Control1.LoginStatus(Session["LOG_CODE"].ToString()) == 0) { Response.Redirect(Session["EXP_PAGE"].ToString()); } else { SSO_Control1.GearUp(ARY1[3].ToString(), ARY1[4].ToString()); } }
private static void ShowIPAddresses(IPInterfaceProperties properties) { throw new NotImplementedException(); }
private static bool HasNetmaskChanged(IPInterfaceProperties oldProperties, IPInterfaceProperties newProperties) { UnicastIPAddressInformation oldIP = null, newIP = null; if (oldProperties.UnicastAddresses.Count != newProperties.UnicastAddresses.Count) return true; foreach (UnicastIPAddressInformation ip in oldProperties.UnicastAddresses) if (ip.Address.AddressFamily == AddressFamily.InterNetwork) { oldIP = ip; break; } foreach (UnicastIPAddressInformation ip in newProperties.UnicastAddresses) if (ip.Address.AddressFamily == AddressFamily.InterNetwork) { newIP = ip; break; } return oldIP != null && newIP != null && !oldIP.IPv4Mask.Equals(newIP.IPv4Mask); }
Win32NetworkInterface2 (Win32_IP_ADAPTER_ADDRESSES addr) { this.addr = addr; mib4 = default (Win32_MIB_IFROW); mib4.Index = addr.Alignment.IfIndex; if (GetIfEntry (ref mib4) != 0) mib4.Index = -1; // unavailable; mib6 = default (Win32_MIB_IFROW); mib6.Index = addr.Ipv6IfIndex; if (GetIfEntry (ref mib6) != 0) mib6.Index = -1; // unavailable; ip4stats = new Win32IPv4InterfaceStatistics (mib4); ip_if_props = new Win32IPInterfaceProperties2 (addr, mib4, mib6); }
public void PopulateIPAddresses(IPInterfaceProperties adapterProperties) { IPAddressCollection dnsServers = adapterProperties.DnsAddresses; if (dnsServers != null) { foreach (IPAddress dns in dnsServers) { lstSocketInformation.Items.Add(String.Format(" DNS Servers ............................. : {0}", dns.ToString() )); } } IPAddressInformationCollection anyCast = adapterProperties.AnycastAddresses; if (anyCast != null) { foreach (IPAddressInformation any in anyCast) { lstSocketInformation.Items.Add(String.Format(" Anycast Address .......................... : {0} {1} {2}", any.Address, any.IsTransient ? "Transient" : "", any.IsDnsEligible ? "DNS Eligible" : "" )); } lstSocketInformation.Items.Add(""); } MulticastIPAddressInformationCollection multiCast = adapterProperties.MulticastAddresses; if (multiCast != null) { foreach (IPAddressInformation multi in multiCast) { lstSocketInformation.Items.Add(String.Format(" Multicast Address ....................... : {0} {1} {2}", multi.Address, multi.IsTransient ? "Transient" : "", multi.IsDnsEligible ? "DNS Eligible" : "" )); } lstSocketInformation.Items.Add(""); } UnicastIPAddressInformationCollection uniCast = adapterProperties.UnicastAddresses; if (uniCast != null) { string lifeTimeFormat = "dddd, MMMM dd, yyyy hh:mm:ss tt"; foreach (UnicastIPAddressInformation uni in uniCast) { DateTime when; lstSocketInformation.Items.Add(String.Format(" Unicast Address ......................... : {0}", uni.Address)); lstSocketInformation.Items.Add(String.Format(" Prefix Origin ........................ : {0}", uni.PrefixOrigin)); lstSocketInformation.Items.Add(String.Format(" Suffix Origin ........................ : {0}", uni.SuffixOrigin)); lstSocketInformation.Items.Add(String.Format(" Duplicate Address Detection .......... : {0}", uni.DuplicateAddressDetectionState)); // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM // if en-us is the current culture. // Calculate the date and time at the end of the lifetimes. when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime); when = when.ToLocalTime(); lstSocketInformation.Items.Add(String.Format(" Valid Life Time ...................... : {0}", when.ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture) )); when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime); when = when.ToLocalTime(); lstSocketInformation.Items.Add(String.Format(" Preferred life time .................. : {0}", when.ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture) )); when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime); when = when.ToLocalTime(); lstSocketInformation.Items.Add(String.Format(" DHCP Leased Life Time ................ : {0}", when.ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture) )); } lstSocketInformation.Items.Add(""); } }
public void LoadIpConfigInformation() { _m_AdapterInformationList = null; _m_CurrentAdapterInformationList = null; CAdapterInformationList.count = 0; //清理链表 /* * while(_m_AdapterInformationList != null) * { * _m_CurrentAdapterInformationList = m_AdapterInformationList; * _m_AdapterInformationList = _m_AdapterInformationList.m_NextAdapter; * * }*/ //获取所有网络接口放在adapters中。 System.Net.NetworkInformation.NetworkInterface[] adapters = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); foreach (System.Net.NetworkInformation.NetworkInterface adapter in adapters) { //未启用的网络接口不要 if (adapter.OperationalStatus != System.Net.NetworkInformation.OperationalStatus.Up) { continue; } //不是以太网和无线网的网络接口不要 if (adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet && adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211 && adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Ppp) { continue; } //虚拟机的网络接口不要 if (adapter.Name.IndexOf("VMware") != -1 || adapter.Name.IndexOf("Virtual") != -1) { continue; } CAdapterInformationList currentAdapter = new CAdapterInformationList(); //获取适配器名称 currentAdapter.m_AdapterInformation.m_Name = adapter.Name; //获取物理地址字节 byte[] physicalAddress = adapter.GetPhysicalAddress().GetAddressBytes(); if (physicalAddress.Length == 0 || physicalAddress.Length != 6) { currentAdapter.m_AdapterInformation.m_Physical = ""; } else { try { currentAdapter.m_AdapterInformation.m_Physical = String.Format("{0:x2}:{1:x2}:{2:x2}:{3:x2}:{4:x2}:{5:x2}", physicalAddress[0], physicalAddress[1], physicalAddress[2], physicalAddress[3], physicalAddress[4], physicalAddress[5]).ToUpper(); } catch (System.Exception) { } } //获取IP地址和Mask地址 System.Net.NetworkInformation.IPInterfaceProperties ipif = adapter.GetIPProperties(); System.Net.NetworkInformation.UnicastIPAddressInformationCollection ipifCollection = ipif.UnicastAddresses; foreach (System.Net.NetworkInformation.UnicastIPAddressInformation ipInformation in ipifCollection) { if (ipInformation.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { currentAdapter.m_AdapterInformation.m_IP = ipInformation.Address.ToString(); currentAdapter.m_AdapterInformation.m_Mask = ipInformation.IPv4Mask.ToString(); } } //获取网关地址,网关一般只有一个 if (ipif.GatewayAddresses != null && ipif.GatewayAddresses.Count != 0) { currentAdapter.m_AdapterInformation.m_Gateway = ((System.Net.NetworkInformation.GatewayIPAddressInformation)(ipif.GatewayAddresses[0])).Address.ToString(); } /* * foreach (System.Net.NetworkInformation.GatewayIPAddressInformation gwInformation in ipif.GatewayAddresses) * { * _m_Gateway = gwInformation.Address.ToString(); * } */ //获取DNS地址,DNS地址一般是两个,有可能没有或一个,或超过两个的情况 //如果超过两个只取前两个 StringBuilder dnsStr = new StringBuilder(30); foreach (System.Net.IPAddress dnsInformation in ipif.DnsAddresses) { dnsStr.Append(dnsInformation.ToString()); dnsStr.Append(','); } dnsStr.Remove(dnsStr.Length - 1, 1); string[] dnsArr = dnsStr.ToString().Split(','); #region switch折叠 switch (dnsArr.Length) { case 0: { currentAdapter.m_AdapterInformation.m_Dns1 = ""; currentAdapter.m_AdapterInformation.m_Dns2 = ""; break; } case 1: { currentAdapter.m_AdapterInformation.m_Dns1 = dnsArr[0]; currentAdapter.m_AdapterInformation.m_Dns2 = ""; break; } case 2: { currentAdapter.m_AdapterInformation.m_Dns1 = dnsArr[0]; currentAdapter.m_AdapterInformation.m_Dns2 = dnsArr[1]; break; } default: { currentAdapter.m_AdapterInformation.m_Dns1 = dnsArr[0]; currentAdapter.m_AdapterInformation.m_Dns2 = dnsArr[1]; break; } } if (_m_AdapterInformationList == null) { _m_AdapterInformationList = currentAdapter; ++CAdapterInformationList.count; //_m_AdapterInformationList.CAdapterInformationList = null; _m_AdapterInformationList.m_NextAdapter = null; _m_CurrentAdapterInformationList = _m_AdapterInformationList; } else { _m_CurrentAdapterInformationList.m_NextAdapter = currentAdapter; ++CAdapterInformationList.count; _m_CurrentAdapterInformationList = currentAdapter; } #endregion } }
private static IEnumerable<IPAddress> GetUnicastAddresses(IPInterfaceProperties ipProps) { // straightforward version (may throw exceptions on Mono 2.10.x/Windows) if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS) { return ipProps.UnicastAddresses.Select(address => address.Address); } var result = new List<IPAddress>(); // catch exceptions to work around Mono 2.10.x bug with some virtual network adapter drivers // http://bugzilla.xamarin.com/show_bug.cgi?id=1254 try { foreach (var address in ipProps.UnicastAddresses) { try { result.Add(address.Address); } catch // NullReferenceException { } } } catch // NullReferenceException { } return result; }
public void DetectActiveNetwork() { Logger.V(">> NetworkDetector.DetectActiveNetwork"); m_activeNetwork = null; m_activeIP = null; NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in adapters) { // skip the non-up network adapter if (!ni.OperationalStatus.Equals(OperationalStatus.Up)) { continue; } // skip the loopback (localhost) network adapter if (ni.NetworkInterfaceType.Equals(NetworkInterfaceType.Loopback)) { continue; } // skip the unknown network adapter if (ni.NetworkInterfaceType.Equals(NetworkInterfaceType.Unknown)) { continue; } #region Determines physical network by Registry string key = @"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" + ni.Id + @"\Connection"; RegistryKey entry = Registry.LocalMachine.OpenSubKey(key, false); if (entry != null) { // Try to get PnpInstanceID; it's a physical LAN card if containing prefix "PCI". string pnpInstanceId = entry.GetValue("PnpInstanceID", "").ToString(); // Try to get MediaSubType; virtual network if 1, wireless network if 2. int mediaSubType = Convert.ToInt32(entry.GetValue("MediaSubType", 0)); if (pnpInstanceId.Length > 3 && pnpInstanceId.Substring(0, 3).Equals("PCI")) { ; // Physical Network } else if (mediaSubType == 1) { ; // Virtual Network, not verified } else if (mediaSubType == 2) { ; // Wireless Network, not verified } else { // VirtualBox Host-Only falls into this case continue; } } else { ; // F5 connection falls into this case, since no regkey corresponding to Id. } #endregion m_activeNetwork = ni; m_activeIP = ni.GetIPProperties(); break; } Logger.V("<< NetworkDetector.DetectActiveNetwork"); }
private string GetIPAddresses(IPInterfaceProperties adapterProperties) { StringBuilder ipAddressesBuilder = new StringBuilder(); IPAddressCollection dnsServers = adapterProperties.DnsAddresses; if (dnsServers.Count > 0) { foreach (IPAddress dns in dnsServers) { ipAddressesBuilder.AppendFormat(" DNS Server ................. : {0}\n", dns.ToString()); } } GatewayIPAddressInformationCollection gateways = adapterProperties.GatewayAddresses; if (gateways.Count > 0) { foreach (GatewayIPAddressInformation gatewayAddresssInfo in gateways) { ipAddressesBuilder.AppendFormat(" Gateway Address ............ : {0}\n", gatewayAddresssInfo.Address); } } IPAddressCollection dhcpServers = adapterProperties.DhcpServerAddresses; if (dhcpServers.Count > 0) { foreach (IPAddress dhcpServer in dhcpServers) { ipAddressesBuilder.AppendFormat(" DHCP Server ................ : {0}\n", dhcpServer); } } IPAddressInformationCollection anyCast = adapterProperties.AnycastAddresses; if (anyCast.Count > 0) { foreach (IPAddressInformation any in anyCast) { ipAddressesBuilder.AppendFormat(" Anycast Address ............ : {0} {1} {2}\n", any.Address, any.IsTransient ? "Transient" : String.Empty, any.IsDnsEligible ? "DNS Eligible" : String.Empty); } } MulticastIPAddressInformationCollection multiCast = adapterProperties.MulticastAddresses; if (multiCast.Count > 0) { foreach (IPAddressInformation multi in multiCast) { ipAddressesBuilder.AppendFormat(" Multicast Address .......... : {0} {1} {2}\n", multi.Address, multi.IsTransient ? "Transient" : String.Empty, multi.IsDnsEligible ? "DNS Eligible" : String.Empty); } } UnicastIPAddressInformationCollection uniCast = adapterProperties.UnicastAddresses; if (uniCast.Count > 0) { string lifeTimeFormat = "dddd, MMMM dd, yyyy hh:mm:ss tt"; foreach (UnicastIPAddressInformation uni in uniCast) { DateTime when; ipAddressesBuilder.AppendFormat(" Unicast Address ............ : {0}\n", uni.Address); ipAddressesBuilder.AppendFormat(" Prefix Origin ............. : {0}\n", uni.PrefixOrigin); ipAddressesBuilder.AppendFormat(" Suffix Origin ............. : {0}\n", uni.SuffixOrigin); ipAddressesBuilder.AppendFormat(" Duplicate Address Detection : {0}\n", uni.DuplicateAddressDetectionState); // Format the lifetimes as Saturday, March 13, 2010 11:33:44 PM // if en-us is the current culture. // Calculate the date and time at the end of the lifetimes. when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime); when = when.ToLocalTime(); ipAddressesBuilder.AppendFormat(" Valid Life Time ........... : {0}\n", when.ToString(lifeTimeFormat, new CultureInfo("en-US"))); when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime); when = when.ToLocalTime(); ipAddressesBuilder.AppendFormat(" Preferred life time ....... : {0}\n", when.ToString(lifeTimeFormat, new CultureInfo("en-US"))); when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime); when = when.ToLocalTime(); ipAddressesBuilder.AppendFormat(" DHCP Leased Life Time ..... : {0}\n", when.ToString(lifeTimeFormat, new CultureInfo("en-US"))); } } return ipAddressesBuilder.ToString(); }
public static void GetRightIPAndPort() { //HDLUDP.ConstPort = 6000; if (CsConst.myintProxy == 0) { string subnetMask = "255.255.255.0"; #region Boolean blnGetMask = NetworkInterface.GetIsNetworkAvailable(); //获取所有网络接口放在adapters中。 if (blnGetMask != false) { NetworkInterface[] adapters = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); foreach (System.Net.NetworkInformation.NetworkInterface adapter in adapters) { //未启用的网络接口不要 if (adapter.OperationalStatus != System.Net.NetworkInformation.OperationalStatus.Up) { continue; } //不是以太网和无线网的网络接口不要 if (adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet && adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211 && adapter.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Ppp) { continue; } //虚拟机的网络接口不要 if (adapter.Name.IndexOf("VMware") != -1 || adapter.Name.IndexOf("Virtual") != -1) { continue; } //获取IP地址和Mask地址 System.Net.NetworkInformation.IPInterfaceProperties ipif = adapter.GetIPProperties(); System.Net.NetworkInformation.UnicastIPAddressInformationCollection ipifCollection = ipif.UnicastAddresses; foreach (System.Net.NetworkInformation.UnicastIPAddressInformation ipInformation in ipifCollection) { if (ipInformation.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { if (ipInformation.Address.ToString() == CsConst.myLocalIP) { subnetMask = ipInformation.IPv4Mask.ToString();//子网掩码 blnGetMask = true; break; } } } if (blnGetMask == true) { break; } } } #endregion byte[] ip = IPAddress.Parse(CsConst.myLocalIP).GetAddressBytes(); byte[] sub = IPAddress.Parse(subnetMask).GetAddressBytes(); // 广播地址=子网按位求反 再 或IP地址 for (int i = 0; i < ip.Length; i++) { ip[i] = (byte)((~sub[i]) | ip[i]); } //CsConst.myDestIP = "255.255.255.255"; CsConst.myDestIP = new IPAddress(ip).ToString(); } }
/// <summary> /// Preparations for monitoring. /// </summary> internal void init() { interfaceStats = nic.GetIPv4Statistics(); props = nic.GetIPProperties(); gateway = props.GatewayAddresses.Count > 0 ? props.GatewayAddresses[props.GatewayAddresses.Count - 1].Address.ToString() : " N/A "; uniCast = props.UnicastAddresses; uniIP = uniCast.Count > 0 ? uniCast[uniCast.Count - 1].Address.ToString() : " N/A "; //the last address in array should be IPv4...but not always... uniIPMask = uniCast.Count > 0 ? uniCast[uniCast.Count - 1].IPv4Mask.ToString() : " N/A "; // Since dlValueOld and ulValueOld are used in method refresh() to calculate network speed, they must have be initialized. this.dlValueOld = interfaceStats.BytesReceived; this.ulValueOld = interfaceStats.BytesSent; }
private static bool HasGatewayChanged(IPInterfaceProperties oldProperties, IPInterfaceProperties newProperties) { GatewayIPAddressInformation oldGW = null, newGW = null; if (oldProperties.GatewayAddresses.Count != newProperties.GatewayAddresses.Count) return true; foreach (GatewayIPAddressInformation gw in oldProperties.GatewayAddresses) if (gw.Address.AddressFamily == AddressFamily.InterNetwork) { oldGW = gw; break; } foreach (GatewayIPAddressInformation gw in newProperties.GatewayAddresses) if (gw.Address.AddressFamily == AddressFamily.InterNetwork) { newGW = gw; break; } return oldGW != null && newGW != null && !oldGW.Address.Equals(newGW.Address); }
/// <summary> /// Gets all addresses for an adapter. /// </summary> /// <param name="interfaceProperties">The interface properties.</param> /// <returns>List of IP Addresses</returns> /// <remarks>For internal use only</remarks> private static List<IPAddressInformation> GetAllAddressesForAdapter(IPInterfaceProperties interfaceProperties) { var adapterAddressList = interfaceProperties.AnycastAddresses.ToList(); adapterAddressList.AddRange(interfaceProperties.MulticastAddresses); adapterAddressList.AddRange(interfaceProperties.UnicastAddresses); return adapterAddressList; }