使用 VB.NET 测试网络延迟

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13401797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:09:27  来源:igfitidea点击:

Test Nework Latency Using VB.NET

vb.net

提问by DylanTheSoldier

Goal:take a list of servers' external ip address. perform a ping to test latency. Like in CMD the ping command shows an average latency. But in visual studio I found the ping only as Boolean for connectivity to a server. How might I go about testing latency to a server to find the fastest connection possible in vb.net? I can't find any other way to do a ping other than. my.computer.network.ping(192.168.1.1). So is there another way to accomplish a latency test in vb.net? Thanks!

目标:获取服务器的外部 IP 地址列表。执行 ping 测试延迟。就像在 CMD 中一样,ping 命令显示平均延迟。但是在 Visual Studio 中,我发现 ping 仅作为连接到服务器的布尔值。我应该如何测试服务器的延迟以在 vb.net 中找到可能的最快连接?除了 ping 之外,我找不到任何其他方法来执行 ping 操作。my.computer.network.ping(192.168.1.1). 那么有没有另一种方法可以在 vb.net 中完成延迟测试?谢谢!

Skill Lvl:close to absolute beginner

技能等级:接近绝对初学者

回答by Carlos Landeras

Here you have a ping example for VB.NET

这里有一个 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)

You will need to Import

您将需要导入

System.Net.NetworkInformation

系统.网络.网络信息

回答by Felix

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")

Source: http://www.dreamincode.net/code/snippet1511.htm

来源:http: //www.dreamincode.net/code/snippet1511.htm

回答by Felix

Just write this code on button click, no need to import anything.

只需在单击按钮时编写此代码,无需导入任何内容。

Dim IP As String = InputBox("Enter Client's IP", "Ping To Client")

Shell("CMD.exe /C ping " & IP & " -t", AppWinStyle.NormalFocus)