Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.NET中查找数据包丢失并跟踪路由_.net_Vb.net_Winforms_Network Programming_Network Protocols - Fatal编程技术网

在.NET中查找数据包丢失并跟踪路由

在.NET中查找数据包丢失并跟踪路由,.net,vb.net,winforms,network-programming,network-protocols,.net,Vb.net,Winforms,Network Programming,Network Protocols,我正在尝试编写代码以捕获计算机上的数据包丢失,但我唯一能够这样做的方法是运行NetStat.exe和TraceRt.exe进程,并将它们捕获到列表框中(使用下面的代码): Private子进程() Dim p As System.Diagnostics.Process 将文件、sTemp、sLineOut、mySent、myRetrans变暗为字符串 以双精度启动 Dim被设置为布尔值 p=新系统.Diagnostics.Process theFile=t.Name 如果File.Exists(

我正在尝试编写代码以捕获计算机上的数据包丢失,但我唯一能够这样做的方法是运行NetStat.exe和TraceRt.exe进程,并将它们捕获到列表框中(使用下面的代码):

Private子进程()
Dim p As System.Diagnostics.Process
将文件、sTemp、sLineOut、mySent、myRetrans变暗为字符串
以双精度启动
Dim被设置为布尔值
p=新系统.Diagnostics.Process
theFile=t.Name
如果File.Exists(“c:\windows\system32\”&theFile)存在,则
theFile=“c:\windows\system32\”&theFile
其他的
MessageBox.Show(“在您的计算机上找不到“&theFile&”文件。”,“文件查找错误!”,MessageBoxButtons.OK,MessageBoxIcon.Error)
如果结束
选择Case t.Name
案例“TraceRt.exe”
p、 StartInfo.Arguments=“-h30 www.stackoverflow.com”
案例“NetStat.exe”
p、 StartInfo.Arguments=“-s-p tcp”
结束选择
尝试
p、 StartInfo.FileName=文件名
p、 StartInfo.CreateNoWindow=True
p、 StartInfo.UseShellExecute=False
p、 StartInfo.RedirectStandardOutput=True
p、 开始()
p、 PriorityClass=System.Diagnostics.ProcessPriorityClass.Normal
sLineOut=“”
不要在p退出时执行此操作
sTemp=p.StandardOutput.ReadLine()
如果是sTemp“”,那么
sLineOut=sLineOut&sTemp&vbNewLine
'发送到列表框
setTrace(sTemp)
如果结束
环
如果sLineOut=”“,则
“清除列表框
clearTrace()
myProcess()
出口接头
如果结束
如果t.Name=“NetStat.exe”,则
尝试
如果lboxTrace.Items.Count<9,则
“清除列表框
clearTrace()
myProcess()
出口接头
如果结束
mySent=“”
mycent=lboxTrace.Items.Item(8)“(“发送的段”)
mycent=Trim(mycent.Replace(“已发送的段”),“”)
mycent=Trim(mycent.Replace(“=”,”))
myRetrans=“”
myRetrans=lboxTrace.Items.Item(9)
myRetrans=Trim(myRetrans.Replace(“重新传输的段”))
myRetrans=修剪(myRetrans.Replace(“=”,”))
intSentStart=Math.Round((myRetrans/mycent)*100,2)
'setTrace将数据发送到列表框
如果intSentStart<2,则
setTrace(“您当前的数据包丢失为:”&intSentStart&“%”)
setTrace(“您的数据包丢失在可接受的范围内。”)
其他的
setTrace(“您当前的数据包丢失为:”&intSentStart&“%”)
setTrace(“您的数据包丢失低于可接受的范围!”)
setTrace(“请联系您的互联网提供商了解您的互联网连接。”)
如果结束
特例
“清除列表框
clearTrace()
myProcess()
出口接头
结束尝试
如果结束
特例
MessageBox.Show(例如Message)
结束尝试
端接头
有没有人有更好的办法来获取这些信息?我宁愿使用托管代码,而不是通过这种方式进行黑客攻击

提前谢谢!
-JFV

不确定这是否是您正在寻找的,但您是否已查看了

编辑:实际上,对于跟踪路由,请在此处查看答案:

对于Netstat,请查看

Private Sub myProcess()
    Dim p As System.Diagnostics.Process
    Dim theFile, sTemp, sLineOut, mySent, myRetrans As String
    Dim intSentStart As Double
    Dim isEnabled As Boolean

    p = New System.Diagnostics.Process
    theFile = t.Name

    If File.Exists("c:\windows\system32\" & theFile) Then
        theFile = "c:\windows\system32\" & theFile
    Else
        MessageBox.Show("Unable to find the " & theFile & " file on your computer.", "File Find Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

    Select Case t.Name
        Case "TraceRt.exe"
            p.StartInfo.Arguments = "-h 30 www.stackoverflow.com"

        Case "NetStat.exe"
            p.StartInfo.Arguments = "-s -p tcp"
    End Select

    Try
        p.StartInfo.FileName = theFile
        p.StartInfo.CreateNoWindow = True
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.Start()
        p.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal

        sLineOut = ""

        Do While Not p.HasExited
            sTemp = p.StandardOutput.ReadLine()
            If sTemp <> "" Then
                sLineOut = sLineOut & sTemp & vbNewLine
                'Send to listbox
                setTrace(sTemp)
            End If
        Loop
        If sLineOut = "" Then
            'Clear Listbox
            clearTrace()
            myProcess()
            Exit Sub
        End If
        If t.Name = "NetStat.exe" Then
            Try
                If lboxTrace.Items.Count < 9 Then
                    'Clear Listbox
                    clearTrace()
                    myProcess()
                    Exit Sub
                End If
                mySent = ""
                mySent = lboxTrace.Items.Item(8) '("Segments Sent")
                mySent = Trim(mySent.Replace("Segments Sent", ""))
                mySent = Trim(mySent.Replace("=", ""))

                myRetrans = ""
                myRetrans = lboxTrace.Items.Item(9)
                myRetrans = Trim(myRetrans.Replace("Segments Retransmitted", ""))
                myRetrans = Trim(myRetrans.Replace("=", ""))

                intSentStart = Math.Round((myRetrans / mySent) * 100, 2)

                'setTrace sends data to the listbox
                If intSentStart < 2 Then
                    setTrace("Your Current Packet Loss is: " & intSentStart & "%.")
                    setTrace("Your packet loss is within acceptable ranges.")
                Else
                    setTrace("Your Current Packet Loss is: " & intSentStart & "%.")
                    setTrace("Your packet loss is below acceptable ranges!")
                    setTrace("Please contact your Internet Provider about your Internet Connection.")
                End If

            Catch ex As Exception
                'Clear Listbox
                clearTrace()
                myProcess()
                Exit Sub
            End Try
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub