• [VB]取得本机的网络连接(类似netstat 命令)


    Option Explicit

    #Const ISDEBUG = False

    Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable As MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)

    Private Type MIB_TCPROW                 ' TCP row
        dwState As Long
        dwLocalAddr As Long                 ' Local  IP
        dwLocalPort As Long                 ' Local  port
        dwRemoteAddr As Long                ' Remote IP
        dwRemotePort As Long                ' Remote port
    End Type

    Private Type MIB_TCPTABLE               ' TCP table
        dwNum_Of_Entries As Long            ' link counts
        TCP_Table(500) As MIB_TCPROW        ' TCP rows
    End Type


    Dim Last_Num_Of_Entries As Long
    Dim TCP1 As MIB_TCPTABLE

    'state
    Dim state As Boolean

    Public Sub Main() 


        Dim i As Long
        Dim Return1 As Long
        Dim Ip_Buf(1 To 4) As Byte
        Dim ConnState, LocalIp, LocalPort, RemoteIp, RemotePort

        Return1 = GetTcpTable(TCP1, Len(TCP1), 1)       ' get TCP link table
        Last_Num_Of_Entries = TCP1.dwNum_Of_Entries
       
        If Return1 = 0 Then
            If Last_Num_Of_Entries <> 0 Then
                On Error GoTo ...

                For i = 0 To TCP1.dwNum_Of_Entries - 1

                    CopyMemory Ip_Buf(1), TCP1.TCP_Table(i).dwRemoteAddr, 4
                    RemoteIp = CStr(Ip_Buf(1)) + "." + CStr(Ip_Buf(2)) + "." + CStr(Ip_Buf(3)) + "." + CStr(Ip_Buf(4))

                    '...

          Next
            End If
        Else
            '...
        End If

    End Sub

  • 相关阅读:
    谈谈近两年维护的一个最最坑爹项目
    LintCode 丑数
    nova 配置文件
    python 网络编程
    python
    python
    cocos2d-js导弹跟踪算法(一边追着目标移动一边旋转角度)
    nginx和apache
    Service绑定模式
    类对象作为成员
  • 原文地址:https://www.cnblogs.com/fjfjfjfjfjfj/p/1858391.html
Copyright © 2020-2023  润新知