目标:获取服务器的外部IP地址列表。执行ping以测试延迟。与CMD类似,ping命令显示平均延迟。但是在visual studio中我发现ping只作为连接到服务器的布尔值。我如何测试服务器的延迟以找到vb.net中可能的最快连接?除了以外,我找不到任何其他方式做ping。 my.computer.network.ping(192.168.1.1)
。那么还有另一种方法可以在vb.net中完成延迟测试吗?谢谢!
技能Lvl:接近绝对初学者
答案 0 :(得分:7)
这里有一个VB.NET的ping示例
Dim host As String = "82.123.23.XX" ' use any other machine name
Dim pingreq As Ping = New Ping()
Dim rep As PingReply = pingreq.Send(host )
Console.WriteLine("Pinging {0} [{1}]", host , rep.Address.ToString())
Console.WriteLine("Reply From {0} : time={1} TTL={2}", rep.Address.ToString(), rep.RoundtripTime, rep.Options.Ttl)
您需要导入
System.Net.NetworkInformation
答案 1 :(得分:2)
Public Shared Function GetPingMs(ByRef hostNameOrAddress As String)
Dim ping As New System.Net.NetworkInformation.Ping
Return ping.Send(hostNameOrAddress).RoundtripTime
End Function
GetPingMs("127.0.0.1")
GetPingMs("www.dreamincode.net")
答案 2 :(得分:0)
只需点击按钮即可编写此代码,无需导入任何内容。
Dim IP As String = InputBox("Enter Client's IP", "Ping To Client")
Shell("CMD.exe /C ping " & IP & " -t", AppWinStyle.NormalFocus)