VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • vb.net 教程 7-1 本地网络信息的获取 6 Tcp/Udp统计数据

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 
通过 IPGlobalProperties的GetTcpIPv4Statistics、GetTcpIPv6Statistics、GetUdpIPv4Statistics、GetUdpIPv6Statistics方法可以获得对应的TCP和UDP统计信息:
 
 
 
 
具体代码如下;
 
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim IPGProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties
 
        TextBox1.Text = "TCP/IPv4统计数据:" & vbCrLf
        Dim TcpS As TcpStatistics = IPGProperties.GetTcpIPv4Statistics
        TextBox1.Text &= "接受的TCP连接请求数:" & TcpS.ConnectionsAccepted & vbCrLf
        TextBox1.Text &= "客户端发出的TCP连接请求数:" & TcpS.ConnectionsInitiated & vbCrLf
        TextBox1.Text &= "建立的TCP连接的总数:" & TcpS.CumulativeConnections & vbCrLf
        TextBox1.Text &= "当前TCP连接数:" & TcpS.CurrentConnections & vbCrLf
        TextBox1.Text &= "收到的TCP错误数:" & TcpS.ErrorsReceived & vbCrLf
        TextBox1.Text &= "失败的TCP连接尝试:" & TcpS.FailedConnectionAttempts & vbCrLf
        TextBox1.Text &= "支持的TCP连接的最大数:" & TcpS.MaximumConnections & vbCrLf
        TextBox1.Text &= "最大重新传输超时值:" & TcpS.MaximumTransmissionTimeout & vbCrLf
        TextBox1.Text &= "最小重新传输超时值:" & TcpS.MinimumTransmissionTimeout & vbCrLf
        TextBox1.Text &= "连接收到的 RST 数据包数:" & TcpS.ResetConnections & vbCrLf
        TextBox1.Text &= "重置标志的TCP段数:" & TcpS.ResetsSent & vbCrLf
        TextBox1.Text &= "收到的TCP段数:" & TcpS.SegmentsReceived & vbCrLf
        TextBox1.Text &= "重新发送的TCP段数:" & TcpS.SegmentsResent & vbCrLf
        TextBox1.Text &= "发送的TCP段数:" & TcpS.SegmentsSent & vbCrLf
 
        TextBox1.Text &= "=============================================" & vbCrLf
        TextBox1.Text &= "TCP/IPv6统计数据:" & vbCrLf
        Dim TcpS6 As TcpStatistics = IPGProperties.GetTcpIPv6Statistics
        TextBox1.Text &= "接受的TCP连接请求数:" & TcpS6.ConnectionsAccepted & vbCrLf
        TextBox1.Text &= "客户端发出的TCP连接请求数:" & TcpS6.ConnectionsInitiated & vbCrLf
        TextBox1.Text &= "建立的TCP连接的总数:" & TcpS6.CumulativeConnections & vbCrLf
        TextBox1.Text &= "当前TCP连接数:" & TcpS6.CurrentConnections & vbCrLf
        TextBox1.Text &= "收到的TCP错误数:" & TcpS6.ErrorsReceived & vbCrLf
        TextBox1.Text &= "失败的TCP连接尝试:" & TcpS6.FailedConnectionAttempts & vbCrLf
        TextBox1.Text &= "支持的TCP连接的最大数:" & TcpS6.MaximumConnections & vbCrLf
        TextBox1.Text &= "最大重新传输超时值:" & TcpS6.MaximumTransmissionTimeout & vbCrLf
        TextBox1.Text &= "最小重新传输超时值:" & TcpS6.MinimumTransmissionTimeout & vbCrLf
        TextBox1.Text &= "连接收到的 RST 数据包数:" & TcpS6.ResetConnections & vbCrLf
        TextBox1.Text &= "重置标志的TCP段数:" & TcpS6.ResetsSent & vbCrLf
        TextBox1.Text &= "收到的TCP段数:" & TcpS6.SegmentsReceived & vbCrLf
        TextBox1.Text &= "重新发送的TCP段数:" & TcpS6.SegmentsResent & vbCrLf
        TextBox1.Text &= "发送的TCP段数:" & TcpS6.SegmentsSent & vbCrLf
 
        TextBox1.Text &= "=============================================" & vbCrLf
        TextBox1.Text &= "UDP/IPv4统计数据:" & vbCrLf
        Dim UdpS As UdpStatistics = IPGProperties.GetUdpIPv4Statistics
        TextBox1.Text &= "已接收的UDP数据报的数量:" & UdpS.DatagramsReceived & vbCrLf
        TextBox1.Text &= "已发送的UDP数据报的数量:" & UdpS.DatagramsSent & vbCrLf
        TextBox1.Text &= "已收到但因端口错误而丢弃的UDP数据报的数量:" & UdpS.IncomingDatagramsDiscarded & vbCrLf
        TextBox1.Text &= "错误而丢弃的UDP数据报的数量:" & UdpS.IncomingDatagramsWithErrors & vbCrLf
        TextBox1.Text &= "侦听UDP数据报的本地终结点的数量:" & UdpS.UdpListeners & vbCrLf
 
        TextBox1.Text &= "=============================================" & vbCrLf
        TextBox1.Text &= "UDP/IPv6统计数据:" & vbCrLf
        Dim UdpS6 As UdpStatistics = IPGProperties.GetUdpIPv6Statistics
        TextBox1.Text &= "已接收的UDP数据报的数量:" & UdpS6.DatagramsReceived & vbCrLf
        TextBox1.Text &= "已发送的UDP数据报的数量:" & UdpS6.DatagramsSent & vbCrLf
        TextBox1.Text &= "已收到但因端口错误而丢弃的UDP数据报的数量:" & UdpS6.IncomingDatagramsDiscarded & vbCrLf
        TextBox1.Text &= "错误而丢弃的UDP数据报的数量:" & UdpS6.IncomingDatagramsWithErrors & vbCrLf
        TextBox1.Text &= "侦听UDP数据报的本地终结点的数量:" & UdpS6.UdpListeners & vbCrLf
 
    End Sub
运行如下:
 
 
 
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
 
学习更多vb.net知识,请参看vb.net 教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/UruseiBest/article/details/81811696

相关教程