private static void PrintIpv6Statistics() { IPGlobalStatistics stats = IPGlobalProperties.GetIPGlobalProperties().GetIPv6GlobalStatistics(); Console.WriteLine("--IPv6 Statistics--"); PrintProperties(stats); }
static void Main(string[] args) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); Console.WriteLine("Domain Name : " + properties.DomainName); Console.WriteLine("Host Name : " + properties.HostName); //Get Active TCP Connections TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); //Get Active TCP Listener IPEndPoint[] endPointsTCP = properties.GetActiveTcpListeners(); //Get Active UDP Listener IPEndPoint[] endPointsUDP = properties.GetActiveUdpListeners(); //Get IP statistics information IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); //Get TCP statistical information TcpStatistics tcpstat = properties.GetTcpIPv4Statistics(); //Get UDP statistical information UdpStatistics udpStat = properties.GetUdpIPv4Statistics(); }
void getUpload() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics stats = null; stats = properties.GetIPv4GlobalStatistics(); Console.WriteLine(stats.ForwardingEnabled); Console.WriteLine(stats.ReceivedPacketsDelivered); }
public static void DisplayIPv4GlobalStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Forwarding enabled ...................... : {0}", ipstat.ForwardingEnabled); Console.WriteLine(" Interfaces .............................. : {0}", ipstat.NumberOfInterfaces); Console.WriteLine(" IP addresses ............................ : {0}", ipstat.NumberOfIPAddresses); Console.WriteLine(" Routes .................................. : {0}", ipstat.NumberOfRoutes); Console.WriteLine(" Default TTL ............................. : {0}", ipstat.DefaultTtl); Console.WriteLine(""); Console.WriteLine(" Inbound Packet Data:"); Console.WriteLine(" Received ............................ : {0}", ipstat.ReceivedPackets); Console.WriteLine(" Forwarded ........................... : {0}", ipstat.ReceivedPacketsForwarded); Console.WriteLine(" Delivered ........................... : {0}", ipstat.ReceivedPacketsDelivered); Console.WriteLine(" Discarded ........................... : {0}", ipstat.ReceivedPacketsDiscarded); Console.WriteLine(" Header Errors ....................... : {0}", ipstat.ReceivedPacketsWithHeadersErrors); Console.WriteLine(" Address Errors ...................... : {0}", ipstat.ReceivedPacketsWithAddressErrors); Console.WriteLine(" Unknown Protocol Errors ............. : {0}", ipstat.ReceivedPacketsWithUnknownProtocol); Console.WriteLine(""); Console.WriteLine(" Outbound Packet Data:"); Console.WriteLine(" Requested ........................... : {0}", ipstat.OutputPacketRequests); Console.WriteLine(" Discarded ........................... : {0}", ipstat.OutputPacketsDiscarded); Console.WriteLine(" No Routing Discards ................. : {0}", ipstat.OutputPacketsWithNoRoute); Console.WriteLine(" Routing Entry Discards .............. : {0}", ipstat.OutputPacketRoutingDiscards); Console.WriteLine(""); Console.WriteLine(" Reassembly Data:"); Console.WriteLine(" Reassembly Timeout .................. : {0}", ipstat.PacketReassemblyTimeout); Console.WriteLine(" Reassemblies Required ............... : {0}", ipstat.PacketReassembliesRequired); Console.WriteLine(" Packets Reassembled ................. : {0}", ipstat.PacketsReassembled); Console.WriteLine(" Packets Fragmented .................. : {0}", ipstat.PacketsFragmented); Console.WriteLine(" Fragment Failures ................... : {0}", ipstat.PacketFragmentFailures); Console.WriteLine(""); }
private void MainForm_Load(object sender, EventArgs e) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); listBoxResult.Items.Add("本机所在域 ...... : " + properties.DomainName); listBoxResult.Items.Add("接收数据包数 .... : " + ipstat.ReceivedPackets); listBoxResult.Items.Add("转发数据包数 .... : " + ipstat.ReceivedPacketsForwarded); listBoxResult.Items.Add("传送数据包数 .... : " + ipstat.ReceivedPacketsDelivered); listBoxResult.Items.Add("丢弃数据包数 .... : " + ipstat.ReceivedPacketsDiscarded); }
//</Snippet15> //<Snippet16> public static void ShowInboundIPErrors() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Inbound Packet Errors:"); Console.WriteLine(" Header Errors ....................... : {0}", ipstat.ReceivedPacketsWithHeadersErrors); Console.WriteLine(" Address Errors ...................... : {0}", ipstat.ReceivedPacketsWithAddressErrors); Console.WriteLine(" Unknown Protocol Errors ............. : {0}", ipstat.ReceivedPacketsWithUnknownProtocol); }
//</Snippet14> //<Snippet15> public static void ShowInboundIPStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Inbound Packet Data:"); Console.WriteLine(" Received ............................ : {0}", ipstat.ReceivedPackets); Console.WriteLine(" Forwarded ........................... : {0}", ipstat.ReceivedPacketsForwarded); Console.WriteLine(" Delivered ........................... : {0}", ipstat.ReceivedPacketsDelivered); Console.WriteLine(" Discarded ........................... : {0}", ipstat.ReceivedPacketsDiscarded); }
//</Snippet16> //<Snippet17> public static void ShowOutboundIPStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Outbound Packet Data:"); Console.WriteLine(" Requested ........................... : {0}", ipstat.OutputPacketRequests); Console.WriteLine(" Discarded ........................... : {0}", ipstat.OutputPacketsDiscarded); Console.WriteLine(" No Routing Discards ................. : {0}", ipstat.OutputPacketsWithNoRoute); Console.WriteLine(" Routing Entry Discards .............. : {0}", ipstat.OutputPacketRoutingDiscards); }
public Page3() { InitializeComponent(); StringBuilder sb = new StringBuilder(); IPGlobalProperties ipg = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipgs = ipg.GetIPv4GlobalStatistics(); sb.AppendLine("本机注册域名" + ipg.DomainName); sb.AppendLine("接收数据包数" + ipgs.ReceivedPackets); sb.AppendLine("转发数据包数" + ipgs.ReceivedPacketsForwarded); sb.AppendLine("传送数据包数" + ipgs.ReceivedPacketsDelivered); sb.AppendLine("丢弃数据包数" + ipgs.ReceivedPacketsDiscarded); text1.Text = sb.ToString(); }
//</Snippet13> //<Snippet14> public static void ShowIPStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Forwarding enabled ...................... : {0}", ipstat.ForwardingEnabled); Console.WriteLine(" Interfaces .............................. : {0}", ipstat.NumberOfInterfaces); Console.WriteLine(" IP addresses ............................ : {0}", ipstat.NumberOfIPAddresses); Console.WriteLine(" Routes .................................. : {0}", ipstat.NumberOfRoutes); Console.WriteLine(" Default TTL ............................. : {0}", ipstat.DefaultTtl); }
//</Snippet17> //<Snippet18> public static void ShowFragmentationStatistics() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine(" Reassembly Data:"); Console.WriteLine(" Reassembly Timeout .................. : {0}", ipstat.PacketReassemblyTimeout); Console.WriteLine(" Reassemblies Required ............... : {0}", ipstat.PacketReassembliesRequired); Console.WriteLine(" Packets Reassembled ................. : {0}", ipstat.PacketsReassembled); Console.WriteLine(" Packets Fragmented .................. : {0}", ipstat.PacketsFragmented); Console.WriteLine(" Fragment Failures ................... : {0}", ipstat.PacketFragmentFailures); }
public Form1() { InitializeComponent(); listBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; //3.22 IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); listBox2.Items.Add("本机所在的域:。。。。" + properties.DomainName); listBox2.Items.Add("接收数据包数:。。。。" + ipstat.ReceivedPackets); listBox2.Items.Add("转发数据包数:。。。。" + ipstat.ReceivedPacketsForwarded); listBox2.Items.Add("传送数据包数:。。。。" + ipstat.ReceivedPacketsDelivered); listBox2.Items.Add("丢弃数据包数:。。。。" + ipstat.ReceivedPacketsDiscarded); }
static void Main(string[] args) { StringBuilder shows = new StringBuilder(); NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); int count = 0; foreach (NetworkInterface adapter in adapters) { count++; shows.AppendLine("-------------------------第" + count + "个适配器信息--------------------------"); shows.AppendLine("描述信息:" + adapter.Description); shows.AppendLine("名称:" + adapter.Name); shows.AppendLine("类型:" + adapter.NetworkInterfaceType); shows.AppendLine("速度" + adapter.Speed / 1000 / 1000 + "M"); byte[] macAddress = adapter.GetPhysicalAddress().GetAddressBytes(); shows.AppendLine("MAC地址:" + BitConverter.ToString(macAddress)); IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); IPAddressCollection dnsServers = adapterProperties.DnsAddresses; if (dnsServers.Count > 0) { foreach (IPAddress dns in dnsServers) { shows.AppendLine("DNS服务器IP地址:" + dns); } } } shows.AppendLine("\n****************************流量包监测*****************************"); IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipStatistics = ipProperties.GetIPv4GlobalStatistics(); shows.AppendLine("本机注册域名 :" + ipProperties.DomainName); shows.AppendLine("接收数据包数 :" + ipStatistics.ReceivedPackets); shows.AppendLine("转发数据包数 :" + ipStatistics.ReceivedPacketsForwarded); shows.AppendLine("传送数据包数 :" + ipStatistics.ReceivedPacketsDelivered); shows.AppendLine("丢弃数据包数 :" + ipStatistics.ReceivedPacketsDiscarded); Console.WriteLine(shows); Console.ReadLine(); }
// returns clients upload speed static double getSpeed() { double speed = 10; /* Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt"); * WebClient wc = new WebClient(); * double starttime = Environment.TickCount; * // download file from the specified URL, and save it to C:\speedtest.txt * wc.DownloadFile(URL, @"C:\Users\winga\Documents\speedtest.txt"); * // get current tickcount * double endtime = Environment.TickCount; * // how many seconds did it take? * // we are calculating this by subtracting starttime from endtime * // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec) * double secs = Math.Floor(endtime - starttime) / 1000; * // round the number of secs and remove the decimal point * double secs2 = Math.Round(secs, 0); * // calculate download rate in kb per sec. * // this is done by dividing 1024 by the number of seconds it * // took to download the file (1024 bytes = 1 kilobyte) * double kbsec = Math.Round(1024 / secs); * try * { * // delete downloaded file * System.IO.File.Delete(@"C:\Users\winga\Documents\speedtest.txt"); * } * catch * { * * }*/ IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics stats = null; stats = properties.GetIPv4GlobalStatistics(); long sp = stats.ReceivedPacketsDelivered; speed = sp; return(speed); }
//数据包检测按钮点击事件 private void button1_Click(object sender, EventArgs e) { //基本定义 IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); TcpConnectionInformation[] tcpConnections = properties.GetActiveTcpConnections(); richTextBox2.AppendText("******\n"); //打印相关数据 richTextBox2.AppendText("本机所在域:" + properties.DomainName + "\n"); richTextBox2.AppendText("接收数据包数:" + ipstat.ReceivedPackets + "\n"); richTextBox2.AppendText("转发数据包数:" + ipstat.ReceivedPacketsForwarded + "\n"); //循环遍历TcpConnectionInformation数组,得到TcpConnectionInformation类型的属性,同时进行打印 foreach (TcpConnectionInformation t in tcpConnections) { string str = ""; str += "Local endpoint:" + t.LocalEndPoint.Address; str += ",Remote endpoint:" + t.RemoteEndPoint.Address; str += ", " + t.State; richTextBox2.AppendText(str + "\n"); } }
public void IPGlobalProperties_IPv4_IPv6_NoErrors_Android(int ipVersion) { IPGlobalProperties gp = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics statistics = ipVersion switch { 4 => gp.GetIPv4GlobalStatistics(), 6 => gp.GetIPv6GlobalStatistics(), _ => throw new ArgumentOutOfRangeException() }; _log.WriteLine($"- IPv{ipVersion} statistics: -"); _log.WriteLine($"Number of interfaces: {statistics.NumberOfInterfaces}"); _log.WriteLine($"Number of IP addresses: {statistics.NumberOfIPAddresses}"); Assert.InRange(statistics.NumberOfInterfaces, 1, int.MaxValue); Assert.InRange(statistics.NumberOfIPAddresses, 1, int.MaxValue); Assert.Throws <PlatformNotSupportedException>(() => statistics.DefaultTtl); Assert.Throws <PlatformNotSupportedException>(() => statistics.ForwardingEnabled); Assert.Throws <PlatformNotSupportedException>(() => statistics.OutputPacketRequests); Assert.Throws <PlatformNotSupportedException>(() => statistics.OutputPacketRoutingDiscards); Assert.Throws <PlatformNotSupportedException>(() => statistics.OutputPacketsDiscarded); Assert.Throws <PlatformNotSupportedException>(() => statistics.OutputPacketsWithNoRoute); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketFragmentFailures); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketReassembliesRequired); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketReassemblyFailures); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketReassemblyTimeout); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketsFragmented); Assert.Throws <PlatformNotSupportedException>(() => statistics.PacketsReassembled); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPackets); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsDelivered); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsDiscarded); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsForwarded); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsWithAddressErrors); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsWithHeadersErrors); Assert.Throws <PlatformNotSupportedException>(() => statistics.ReceivedPacketsWithUnknownProtocol); Assert.Throws <PlatformNotSupportedException>(() => statistics.NumberOfRoutes); }
}//获取hosts void getnetinfo()//获取网络信息 { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();//获取本地计算机上网络接口的对象 foreach (NetworkInterface adapter in adapters) { if (adapter.Description.Contains("TAP") || adapter.Description.Contains("Virtual") || adapter.Description.Contains("VPN") || adapter.Description.Contains("Bluetooth") || adapter.Description.Contains("Loopback")) { //过滤其他适配器 } else { if (adapter.OperationalStatus.ToString() == "Up") { IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息 UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses; foreach (UnicastIPAddressInformation ipadd in ipCollection) { //InterNetwork IPV4地址 InterNetworkV6 IPV6地址 //Max MAX 位址 if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork) { //判断是否为ipv4 ipv4addr = ipadd.Address.ToString(); //获取ip ipv4mask = ipadd.IPv4Mask.ToString(); //子网掩码 } } if (ip.UnicastAddresses.Count > 0) { //ipv4addr = ip.UnicastAddresses[0].Address.ToString(); //IP地址 //ipv4mask = ip.UnicastAddresses[0].IPv4Mask.ToString(); //子网掩码 } if (ip.GatewayAddresses.Count > 0) { ipv4gate = ip.GatewayAddresses[0].Address.ToString(); //默认网关 } if (ip.DnsAddresses.Count > 0) { ipv4dns1 = ip.DnsAddresses[0].ToString(); //首选DNS服务器地址 if (ip.DnsAddresses.Count > 1) { ipv4dns2 = ip.DnsAddresses[1].ToString(); //备用DNS服务器地址 } else { ipv4dns2 = "自动获取"; } } else { ipv4dns1 = "自动获取"; ipv4dns2 = "自动获取"; } IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics(); string ReceivedPackets = ipstat.ReceivedPackets.ToString(); //接收数据包 string ReceivedPacketsForwarded = ipstat.ReceivedPacketsForwarded.ToString(); //转发数据包 string ReceivedPacketsDelivered = ipstat.ReceivedPacketsDelivered.ToString(); //传送数据包 string ReceivedPacketsDiscarded = ipstat.ReceivedPacketsDiscarded.ToString(); //丢弃数据包 lb4netdevice.Text = adapter.Name; lb4ipv4.Text = ipv4addr; lb4mask.Text = ipv4mask; lb4gate.Text = ipv4gate; lb4dns1.Text = ipv4dns1; lb4dns2.Text = ipv4dns2; lb4datarec.Text = ReceivedPackets; lb4datasend.Text = ReceivedPacketsDelivered; lb4dataudp.Text = ReceivedPacketsForwarded; lb4datalost.Text = ReceivedPacketsDiscarded; } } } }
public NetworkTraffic() { _startTime = DateTime.MinValue; ipstat = properties.GetIPv4GlobalStatistics(); }
private string GetIPGlobalStatistics( NetworkInterfaceComponent version, IPGlobalProperties properties) { IPGlobalStatistics ipStat = null; StringBuilder ipStatBuilder = new StringBuilder(); try { switch (version) { case NetworkInterfaceComponent.IPv4: ipStat = properties.GetIPv4GlobalStatistics(); ipStatBuilder.Append("IPv4 Global Statistics\n"); break; case NetworkInterfaceComponent.IPv6: ipStat = properties.GetIPv6GlobalStatistics(); ipStatBuilder.Append("IPv6 Global Statistics:"); break; default: throw new ArgumentException("No such IP version"); } } catch (NetworkInformationException) { return(String.Empty); } ipStatBuilder.Append("=================================================\n"); ipStatBuilder.AppendFormat(" Computer name ................. : {0}\n", properties.HostName); ipStatBuilder.AppendFormat(" Domain name ................... : {0}\n", properties.DomainName); ipStatBuilder.AppendFormat(" Node type ..................... : {0}\n", properties.NodeType); ipStatBuilder.AppendFormat(" DHCP scope .................... : {0}\n", properties.DhcpScopeName); ipStatBuilder.AppendFormat(" Is WINS proxy ................. : {0}\n", properties.IsWinsProxy); ipStatBuilder.AppendFormat(" Forwarding enabled ............ : {0}\n", ipStat.ForwardingEnabled); ipStatBuilder.AppendFormat(" Interfaces .................... : {0}\n", ipStat.NumberOfInterfaces); ipStatBuilder.AppendFormat(" IP addresses .................. : {0}\n", ipStat.NumberOfIPAddresses); ipStatBuilder.AppendFormat(" Routes ........................ : {0}\n", ipStat.NumberOfRoutes); ipStatBuilder.AppendFormat(" Default TTL ................... : {0}\n\n", ipStat.DefaultTtl); ipStatBuilder.AppendFormat(" Inbound Packet Data:\n"); ipStatBuilder.AppendFormat(" Received ..................... : {0}\n", ipStat.ReceivedPackets); ipStatBuilder.AppendFormat(" Forwarded .................... : {0}\n", ipStat.ReceivedPacketsForwarded); ipStatBuilder.AppendFormat(" Delivered .................... : {0}\n", ipStat.ReceivedPacketsDelivered); ipStatBuilder.AppendFormat(" Discarded .................... : {0}\n", ipStat.ReceivedPacketsDiscarded); ipStatBuilder.AppendFormat(" Header Errors ................ : {0}\n", ipStat.ReceivedPacketsWithHeadersErrors); ipStatBuilder.AppendFormat(" Address Errors ............... : {0}\n", ipStat.ReceivedPacketsWithAddressErrors); ipStatBuilder.AppendFormat(" Unknown Protocol Errors ...... : {0}\n\n", ipStat.ReceivedPacketsWithUnknownProtocol); ipStatBuilder.AppendFormat(" Outbound Packet Data:\n"); ipStatBuilder.AppendFormat(" Requested .................... : {0}\n", ipStat.OutputPacketRequests); ipStatBuilder.AppendFormat(" Discarded .................... : {0}\n", ipStat.OutputPacketsDiscarded); ipStatBuilder.AppendFormat(" No Routing Discards .......... : {0}\n", ipStat.OutputPacketsWithNoRoute); ipStatBuilder.AppendFormat(" Routing Entry Discards ....... : {0}\n\n", ipStat.OutputPacketRoutingDiscards); ipStatBuilder.AppendFormat(" Reassembly Data:\n"); ipStatBuilder.AppendFormat(" Reassembly Timeout ........... : {0}\n", ipStat.PacketReassemblyTimeout); ipStatBuilder.AppendFormat(" Reassemblies Required ........ : {0}\n", ipStat.PacketReassembliesRequired); ipStatBuilder.AppendFormat(" Reassembly Failures .......... : {0}\n", ipStat.PacketReassemblyFailures); ipStatBuilder.AppendFormat(" Packets Reassembled .......... : {0}\n", ipStat.PacketsReassembled); ipStatBuilder.AppendFormat(" Packets Fragmented ........... : {0}\n", ipStat.PacketsFragmented); ipStatBuilder.AppendFormat(" Fragment Failures ............ : {0}\n", ipStat.PacketFragmentFailures); return(ipStatBuilder.ToString()); }
//<Snippet1> public static void ShowIPStatistics(NetworkInterfaceComponent version) { //<Snippet20> IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipstat = null; switch (version) { case NetworkInterfaceComponent.IPv4: ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine("{0}IPv4 Statistics ", Environment.NewLine); break; case NetworkInterfaceComponent.IPv6: ipstat = properties.GetIPv4GlobalStatistics(); Console.WriteLine("{0}IPv6 Statistics ", Environment.NewLine); break; default: throw new ArgumentException("version"); // break; } //</Snippet20> Console.WriteLine(" Forwarding enabled ...................... : {0}", ipstat.ForwardingEnabled); Console.WriteLine(" Interfaces .............................. : {0}", ipstat.NumberOfInterfaces); Console.WriteLine(" IP addresses ............................ : {0}", ipstat.NumberOfIPAddresses); Console.WriteLine(" Routes .................................. : {0}", ipstat.NumberOfRoutes); Console.WriteLine(" Default TTL ............................. : {0}", ipstat.DefaultTtl); Console.WriteLine(""); Console.WriteLine(" Inbound Packet Data:"); Console.WriteLine(" Received ............................ : {0}", ipstat.ReceivedPackets); Console.WriteLine(" Forwarded ........................... : {0}", ipstat.ReceivedPacketsForwarded); Console.WriteLine(" Delivered ........................... : {0}", ipstat.ReceivedPacketsDelivered); Console.WriteLine(" Discarded ........................... : {0}", ipstat.ReceivedPacketsDiscarded); Console.WriteLine(" Header Errors ....................... : {0}", ipstat.ReceivedPacketsWithHeadersErrors); Console.WriteLine(" Address Errors ...................... : {0}", ipstat.ReceivedPacketsWithAddressErrors); Console.WriteLine(" Unknown Protocol Errors ............. : {0}", ipstat.ReceivedPacketsWithUnknownProtocol); Console.WriteLine(""); Console.WriteLine(" Outbound Packet Data:"); Console.WriteLine(" Requested ........................... : {0}", ipstat.OutputPacketRequests); Console.WriteLine(" Discarded ........................... : {0}", ipstat.OutputPacketsDiscarded); Console.WriteLine(" No Routing Discards ................. : {0}", ipstat.OutputPacketsWithNoRoute); Console.WriteLine(" Routing Entry Discards .............. : {0}", ipstat.OutputPacketRoutingDiscards); Console.WriteLine(""); Console.WriteLine(" Reassembly Data:"); Console.WriteLine(" Reassembly Timeout .................. : {0}", ipstat.PacketReassemblyTimeout); Console.WriteLine(" Reassemblies Required ............... : {0}", ipstat.PacketReassembliesRequired); Console.WriteLine(" Packets Reassembled ................. : {0}", ipstat.PacketsReassembled); Console.WriteLine(" Packets Fragmented .................. : {0}", ipstat.PacketsFragmented); Console.WriteLine(" Fragment Failures ................... : {0}", ipstat.PacketFragmentFailures); Console.WriteLine(""); }
public static DataTable GetNetworkingStatiticsTable(NetworkInterfaceComponent version) { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); IPGlobalStatistics ipStat = null; DataTable statsTable = new DataTable("Network Statistics"); statsTable.Columns.Add("Stats Group", System.Type.GetType("System.String")); statsTable.Columns.Add("Item", System.Type.GetType("System.String")); statsTable.Columns.Add("Stats", System.Type.GetType("System.String")); switch (version) { case NetworkInterfaceComponent.IPv4: ipStat = properties.GetIPv4GlobalStatistics(); break; case NetworkInterfaceComponent.IPv6: ipStat = properties.GetIPv6GlobalStatistics(); break; default: throw (new Exception("Invalid version for NetworkInterfaceComponent")); } DataRow row = default(DataRow); //******************************************* // GENERAL STATISTICS //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "Forwarding enabled"; row["Stats"] = ipStat.ForwardingEnabled.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "No. Interfaces"; row["Stats"] = ipStat.NumberOfInterfaces.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "No. IP addresses"; row["Stats"] = ipStat.NumberOfIPAddresses.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "No. Routes"; row["Stats"] = ipStat.NumberOfRoutes.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "Default TTL"; row["Stats"] = ipStat.DefaultTtl.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "General"; row["Item"] = "Active/Open TCP Ports"; SortedList list = GetOpenTCPPorts(); row["Stats"] = list.Count; statsTable.Rows.Add(row); //******************************************* // INBOUND PACKET DATA row = statsTable.NewRow(); row["Stats Group"] = ""; row["Item"] = ""; row["Stats"] = ""; statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Received"; row["Stats"] = ipStat.ReceivedPackets.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Forwarded"; row["Stats"] = ipStat.ReceivedPacketsForwarded.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Delivered"; row["Stats"] = ipStat.ReceivedPacketsDelivered.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Discarded"; row["Stats"] = ipStat.ReceivedPacketsDiscarded.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Header Errors"; row["Stats"] = ipStat.ReceivedPacketsWithHeadersErrors.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Address Errors"; row["Stats"] = ipStat.ReceivedPacketsWithAddressErrors.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Inbound Packet Data"; row["Item"] = "Unknown Protocol Errors"; row["Stats"] = ipStat.ReceivedPacketsWithUnknownProtocol.ToString(); statsTable.Rows.Add(row); //******************************************* //OUTBOUND PACKET DATA //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = ""; row["Item"] = ""; row["Stats"] = ""; statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Outbound Packet Data"; row["Item"] = "Requested"; row["Stats"] = ipStat.OutputPacketRequests.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Outbound Packet Data"; row["Item"] = "Discarded"; row["Stats"] = ipStat.OutputPacketsDiscarded.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Outbound Packet Data"; row["Item"] = "No Routing Discards"; row["Stats"] = ipStat.OutputPacketsWithNoRoute.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Outbound Packet Data"; row["Item"] = "Routing Entry Discards"; row["Stats"] = ipStat.OutputPacketRoutingDiscards.ToString(); statsTable.Rows.Add(row); //******************************************* //REASSEMBLY PACKET DATA //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = ""; row["Item"] = ""; row["Stats"] = ""; statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Reassembly Data"; row["Item"] = "Reassembly Timeout"; row["Stats"] = ipStat.PacketReassemblyTimeout.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Reassembly Data"; row["Item"] = "Reassemblies Required"; row["Stats"] = ipStat.PacketReassembliesRequired.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Reassembly Data"; row["Item"] = "Packets Reassembled"; row["Stats"] = ipStat.PacketsReassembled.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Reassembly Data"; row["Item"] = "Packets Fragmented"; row["Stats"] = ipStat.PacketsFragmented.ToString(); statsTable.Rows.Add(row); //------------------------------------------- row = statsTable.NewRow(); row["Stats Group"] = "Reassembly Data"; row["Item"] = "Fragment Failures"; row["Stats"] = ipStat.PacketFragmentFailures.ToString(); statsTable.Rows.Add(row); return(statsTable); }
// Display the global IP statisitcs for given IPGlobalStatistics // object. private static void DisplayIPStatistics(IPGlobalStatistics ipStat) { Console.WriteLine( equalsFormatString, "Packets Received", ipStat.ReceivedPackets); Console.WriteLine( equalsFormatString, "Received Header Errors", ipStat.ReceivedPacketsWithHeadersErrors); Console.WriteLine( equalsFormatString, "Received Address Errors", ipStat.ReceivedPacketsWithAddressErrors); Console.WriteLine( equalsFormatString, "Datagrams Forwarded", ipStat.ReceivedPacketsForwarded); Console.WriteLine( equalsFormatString, "Unknown Protocols Received", ipStat.ReceivedPacketsWithUnknownProtocol); Console.WriteLine( equalsFormatString, "Received Packets Discarded", ipStat.ReceivedPacketsDiscarded); Console.WriteLine( equalsFormatString, "Received Packets Delivered", ipStat.ReceivedPacketsDelivered); Console.WriteLine( equalsFormatString, "Output Requests", ipStat.OutputPacketRequests); Console.WriteLine( equalsFormatString, "Routing Discards", ipStat.OutputPacketRoutingDiscards); Console.WriteLine( equalsFormatString, "Discarded Output Packets", ipStat.OutputPacketsDiscarded); Console.WriteLine( equalsFormatString, "Output Packet No Route", ipStat.OutputPacketsWithNoRoute); Console.WriteLine( equalsFormatString, "Reassembly Required", ipStat.PacketReassembliesRequired); Console.WriteLine( equalsFormatString, "Reassembly Successful", ipStat.PacketsReassembled); Console.WriteLine( equalsFormatString, "Reassembly Failures", ipStat.PacketReassemblyFailures); Console.WriteLine( equalsFormatString, "Datagrams Successfuly Fragmented", ipStat.PacketsFragmented); Console.WriteLine( equalsFormatString, "Datagrams Failing Fragmentation", ipStat.PacketFragmentFailures); Console.WriteLine( equalsFormatString, "Fragments Created", ipStat.PacketsFragmented); }