static public string SystemDetails() { string info = "System Details" + Environment.NewLine; try { List <NetworkInfoModel> aNics = NetworkInfo.GetAllNetworkInterfaces(); // os details info += Environment.NewLine + "OS Info: " + Linn.SystemInfo.VersionString + Environment.NewLine; info += "OS Platform: " + Environment.OSVersion.Platform.ToString() + Environment.NewLine; info += "OS Version: " + Environment.OSVersion.Version.ToString() + Environment.NewLine; info += "OS Service Pack: " + Linn.SystemInfo.ServicePack + Environment.NewLine; // system details info += Environment.NewLine + "Runtime language version: " + Environment.Version.ToString() + Environment.NewLine; info += "Computer Name: " + Linn.SystemInfo.ComputerName + Environment.NewLine; // ssdp service info += Environment.NewLine + "SSDP Service Name: " + Linn.ServiceInfo.DisplayName + Environment.NewLine; info += "SSDP Service State: " + Linn.ServiceInfo.Status.ToString() + Environment.NewLine; // network setup info += Environment.NewLine + "Network Setup:" + Environment.NewLine + NetworkInterfaceCards(aNics) + Environment.NewLine; } catch (Exception e) { info += "Error gathering system details: " + e.Message + Environment.NewLine; } return(info); }
private NetworkInfoModel GetInterface(string aNetworkInterface) { IPAddress addr = null; try { addr = IPAddress.Parse(aNetworkInterface); } catch (FormatException) { } IList <NetworkInfoModel> ifaces = NetworkInfo.GetAllNetworkInterfaces(); foreach (NetworkInfoModel iface in ifaces) { if (addr != null && addr != IPAddress.None) { if (iface.IPAddress.Equals(addr)) { return(iface); } } else { if (iface.Name == aNetworkInterface) { return(iface); } } } return(null); }
public void NetworkChanged() { NetworkInterface newInterface = null; lock (this) { // rebuild list of available interfaces iAllowedInterfaces = new List <NetworkInterface>(); iAllowedInterfaces.Add(new NetworkInterface()); foreach (NetworkInfoModel i in NetworkInfo.GetAllNetworkInterfaces()) { if (i.OperationalStatus == EOperationalStatus.eUp || i.OperationalStatus == EOperationalStatus.eUnknown) { // don't add 3G network card on iPads/iPhones if (i.Name != "pdp_ip0") { iAllowedInterfaces.Add(new NetworkInterface(i)); } } } // send to user log string userLogMsg = DateTime.Now + ": Network interface event received. Available interfaces:"; for (int i = 1; i < iAllowedInterfaces.Count; i++) { userLogMsg += Environment.NewLine + DateTime.Now + ": " + iAllowedInterfaces[i].ToString(); } UserLog.WriteLine(userLogMsg); // set the default interface - if there is only 1 real interface - set this as default if (iAllowedInterfaces.Count == 2) { iDefault = iAllowedInterfaces[1]; } else { iDefault = iAllowedInterfaces[0]; } // update the existing interface switch (iInterface.Status) { case NetworkInterface.EStatus.eUnconfigured: if (iDefault.Status != NetworkInterface.EStatus.eUnconfigured) { // interface unconfigured -> available/unavailable default newInterface = iDefault; } break; case NetworkInterface.EStatus.eUnavailable: { NetworkInterface found = FindInterface(iInterface.Name); if (found != null && found.Status == NetworkInterface.EStatus.eAvailable) { // interface unavailable -> available newInterface = found; } } break; case NetworkInterface.EStatus.eAvailable: { NetworkInterface found = FindInterface(iInterface.Name); if (found != null) { if (found.Status == NetworkInterface.EStatus.eAvailable) { if (!iInterface.Info.IPAddress.Equals(found.Info.IPAddress)) { // interface available -> available (ip address change) newInterface = found; } } else { // interface available -> unavailable newInterface = found; } } else { // interface available -> unavailable newInterface = new NetworkInterface(iInterface.Name); } } break; } if (newInterface != null) { iInterface = newInterface; } Trace.WriteLine(Trace.kCore, "OptionNetworkInterface.NetworkChange(): Network interface event - " + iInterface + " -> " + newInterface); UserLog.WriteLine(DateTime.Now + ": Network interface event - " + iInterface + " -> " + newInterface); } EventHandler <EventArgs> eventAllowedChanged = EventAllowedChanged; if (eventAllowedChanged != null) { eventAllowedChanged(this, EventArgs.Empty); } EventHandler <EventArgs> eventValueChanged = EventValueChanged; if (newInterface != null && eventValueChanged != null) { eventValueChanged(this, EventArgs.Empty); } }