vb.net 第二十节 测定到指定目的地往返时间和跳跃数

Posted VB.Net

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb.net 第二十节 测定到指定目的地往返时间和跳跃数相关的知识,希望对你有一定的参考价值。

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 

Public Class Form21
    'BOOL GetRTTAndHopCount(_In_  IPAddr DestIpAddress, _Out_ PULONG HopCount,  _In_  ULong  MaxHops,  _Out_ PULONG RTT);


    'Private Declare Function GetRTTAndHopCount Lib "iphlpapi.dll" (ByVal DestIpAddress As Long, HopCount As Long, MaxHops As Long, RTT As Long) As Long
    'Private Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long

    Private Declare Function GetRTTAndHopCount Lib "iphlpapi.dll" (ByVal DestIpAddress As Integer, ByRef HopCount As Integer, ByVal MaxHops As Integer, ByRef RTT As Integer) As Integer
    Private Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Integer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim returnValue As Integer
        Dim DestIpAddress As Integer
        Dim HopCount As Integer
        Dim MaxHops As Integer
        Dim RTT As Integer

        DestIpAddress = inet_addr("14.215.177.39")    '这里是探测www.baidu.com
        MaxHops = 50

        returnValue = GetRTTAndHopCount(DestIpAddress, HopCount, MaxHops, RTT)

        TextBox1.Text = "目的地IP:" & IntToIP(DestIpAddress) & vbCrLf
        TextBox1.Text &= "跳跃数目:" & HopCount & vbCrLf
        TextBox1.Text &= "往返时间:" & RTT & "ms"

    End Sub

    Private Function IntToIP(ByVal intAddr As Integer) As String
        Dim bteIp() As Byte
        bteIp = BitConverter.GetBytes(intAddr)
        Dim ip As String = ""
        For i As Integer = 0 To bteIp.Length - 1
            ip &= bteIp(i).ToString & "."
        Next

        Return ip.Substring(0, ip.Length - 1)
    End Function
End Class

 

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

以上是关于vb.net 第二十节 测定到指定目的地往返时间和跳跃数的主要内容,如果未能解决你的问题,请参考以下文章

vb.net 第二十一节 增加和删除一个IP地址

Scala入门到精通——第二十节 类型參数

vb.net 第十节 获取本机已探测的IP – 物理地址映射表 GetIpNetTable

第二十节,基本数据类型,集合set综合应用新数据更新老数据

php增删改查实例第二十节 - 把用户管理页面集成到main.php中

centos mysql 优化 第二十节课