public void ShowNetworkInterfaces() { IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); ConsoleWriteLine(computerProperties.HostName.ToString()); ConsoleWriteLine(computerProperties.DomainName.ToString()); if (nics == null || nics.Length < 1) { ConsoleWriteLine(" No network interfaces found."); return; } ConsoleWriteLine(nics.Length.ToString()); foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); ConsoleWriteLine(adapter.Description); ConsoleWriteLine(String.Empty.PadLeft(adapter.Description.Length, '=')); ConsoleWriteLine(adapter.NetworkInterfaceType.ToString()); ConsoleWriteLine(adapter.GetPhysicalAddress().ToString()); ConsoleWriteLine(adapter.OperationalStatus.ToString()); string versions = ""; // Create a display string for the supported IP versions. if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { versions = "IPv4"; } if (adapter.Supports(NetworkInterfaceComponent.IPv6)) { if (versions.Length > 0) { versions += " "; } versions += "IPv6"; } ConsoleWriteLine(versions.ToString()); ConsoleWriteLine(properties.ToString()); ShowIPAddresses(properties); // The following information is not useful for loopback adapters. if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } ConsoleWriteLine(properties.DnsSuffix.ToString()); string label; if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties(); ConsoleWriteLine(ipv4.Mtu.ToString()); if (ipv4.UsesWins) { IPAddressCollection winsServers = properties.WinsServersAddresses; if (winsServers.Count > 0) { foreach (var winsServer in winsServers) { ConsoleWriteLine(winsServer.ToString()); } } } } ConsoleWriteLine(properties.IsDnsEnabled.ToString()); ConsoleWriteLine(properties.IsDynamicDnsEnabled.ToString()); ConsoleWriteLine(adapter.IsReceiveOnly.ToString()); ConsoleWriteLine(adapter.SupportsMulticast.ToString()); ShowInterfaceStatistics(adapter); } }
private void loadUnitData() { string hostName = Dns.GetHostName(); HName.Text = hostName; OwnIP.Text = Dns.GetHostByName(hostName).AddressList[0].ToString(); string externalip = new WebClient().DownloadString("http://icanhazip.com"); gIP.Text = externalip; if (CheckForInternetConnection()) { connected.Text = "YES"; } else { connected.Text = "NO"; return; } var macAddr = ( from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString() ).FirstOrDefault(); mac.Text = macAddr; StringBuilder sb = new StringBuilder(); IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); sb.AppendLine(string.Format("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName)); if (nics == null || nics.Length < 1) { sb.AppendLine(" No network interfaces found."); return; } sb.AppendLine(string.Format(" Number of interfaces .................... : {0}", nics.Length)); foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); sb.AppendLine(); sb.AppendLine(adapter.Description); sb.AppendLine(String.Empty.PadLeft(adapter.Description.Length, '=')); sb.AppendLine(string.Format(" Interface type .......................... : {0}", adapter.NetworkInterfaceType)); sb.AppendLine(string.Format(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString())); sb.AppendLine(string.Format(" Operational status ...................... : {0}", adapter.OperationalStatus)); string versions = ""; // Create a display string for the supported IP versions. if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { versions = "IPv4"; } if (adapter.Supports(NetworkInterfaceComponent.IPv6)) { if (versions.Length > 0) { versions += " "; } versions += "IPv6"; } sb.AppendLine(string.Format(" IP version .............................. : {0}", versions)); sb.AppendLine(string.Format(properties.ToString())); // The following information is not useful for loopback adapters. if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } sb.AppendLine(string.Format(" DNS suffix .............................. : {0}", properties.DnsSuffix)); string label; if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties(); sb.AppendLine(string.Format(" MTU...................................... : {0}", ipv4.Mtu)); if (ipv4.UsesWins) { IPAddressCollection winsServers = properties.WinsServersAddresses; if (winsServers.Count > 0) { label = " WINS Servers ............................ :"; sb.AppendLine(string.Format(label, winsServers)); } } } sb.AppendLine(string.Format(" DNS enabled ............................. : {0}", properties.IsDnsEnabled)); sb.AppendLine(string.Format(" Dynamically configured DNS .............. : {0}", properties.IsDynamicDnsEnabled)); sb.AppendLine(string.Format(" Receive Only ............................ : {0}", adapter.IsReceiveOnly)); sb.AppendLine(string.Format(" Multicast ............................... : {0}", adapter.SupportsMulticast)); sb.AppendLine("Speed Test : "); NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { sb.AppendLine(string.Format(" Bytes Sent: {0}", ni.GetIPv4Statistics().BytesSent)); sb.AppendLine(string.Format(" Bytes Received: {0}", ni.GetIPv4Statistics().BytesReceived)); } } // ipconfig/all sb.AppendLine("ipconfig/all"); sb.AppendLine(runProcess("ipconfig", "/all")); // "new view"; // router sb.AppendLine("net view"); sb.AppendLine(runProcess("net", "view")); // "arp -a"; // local units sb.AppendLine("arp -a"); sb.AppendLine(runProcess("arp", "-a")); // "netstat –ano"; // all connections sb.AppendLine("netstat –ano"); sb.AppendLine(runProcess("netstat", "-o")); // "nslookup " + externalip.Replace("\n", ""); // all connections sb.AppendLine("nslookup " + externalip.Replace("\n", "")); sb.AppendLine(runProcess("nslookup", externalip.Replace("\n", ""))); richTextBox1.Text = sb.ToString(); }
private void loadNetwork() { StringBuilder sb = new StringBuilder(); IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); sb.AppendLine(string.Format("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName)); if (nics == null || nics.Length < 1) { sb.AppendLine(" No network interfaces found."); return; } sb.AppendLine(string.Format(" Number of interfaces .................... : {0}", nics.Length)); foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); sb.AppendLine(); sb.AppendLine(adapter.Description); sb.AppendLine(String.Empty.PadLeft(adapter.Description.Length, '=')); sb.AppendLine(string.Format(" Interface type .......................... : {0}", adapter.NetworkInterfaceType)); sb.AppendLine(string.Format(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString())); sb.AppendLine(string.Format(" Operational status ...................... : {0}", adapter.OperationalStatus)); string versions = ""; // Create a display string for the supported IP versions. if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { versions = "IPv4"; } if (adapter.Supports(NetworkInterfaceComponent.IPv6)) { if (versions.Length > 0) { versions += " "; } versions += "IPv6"; } sb.AppendLine(string.Format(" IP version .............................. : {0}", versions)); sb.AppendLine(string.Format(properties.ToString())); // The following information is not useful for loopback adapters. if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } sb.AppendLine(string.Format(" DNS suffix .............................. : {0}", properties.DnsSuffix)); string label; if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties(); sb.AppendLine(string.Format(" MTU...................................... : {0}", ipv4.Mtu)); if (ipv4.UsesWins) { IPAddressCollection winsServers = properties.WinsServersAddresses; if (winsServers.Count > 0) { label = " WINS Servers ............................ :"; sb.AppendLine(string.Format(label, winsServers)); } } } sb.AppendLine(string.Format(" DNS enabled ............................. : {0}", properties.IsDnsEnabled)); sb.AppendLine(string.Format(" Dynamically configured DNS .............. : {0}", properties.IsDynamicDnsEnabled)); sb.AppendLine(string.Format(" Receive Only ............................ : {0}", adapter.IsReceiveOnly)); sb.AppendLine(string.Format(" Multicast ............................... : {0}", adapter.SupportsMulticast)); sb.AppendLine(); richTextBox7.Text = sb.ToString(); } }