⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 电子书“Visual Basic 6 网络编程实例教程.rar”
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "获取IP地址"
   ClientHeight    =   3180
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8325
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3180
   ScaleWidth      =   8325
   StartUpPosition =   2  '屏幕中心
   Begin MSComctlLib.ListView LvwIpTable 
      Height          =   2295
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   8055
      _ExtentX        =   14208
      _ExtentY        =   4048
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.CommandButton CmdGetIpTable 
      Caption         =   "运行(&R)"
      Default         =   -1  'True
      Height          =   495
      Left            =   3120
      TabIndex        =   0
      Top             =   2640
      Width           =   2175
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub CmdGetIpTable_Click()
    Dim IPAddrRow As MIB_IPADDRROW
    Dim buff() As Byte
    Dim cbRequired As Long
    Dim nStructSize As Long
    Dim nRows As Long
    Dim cnt As Long
    Dim itmx As ListItem
    Call GetIpAddrTable(ByVal 0&, cbRequired, 1)
    If cbRequired > 0 Then
        ReDim buff(0 To cbRequired - 1) As Byte
        If GetIpAddrTable(buff(0), cbRequired, 1) = ERROR_SUCCESS Then
            LvwIpTable.ListItems.Clear
            nStructSize = LenB(IPAddrRow)
            '前4个字节是一个长整形,指明了IP地址表的入口
            CopyMemory nRows, buff(0), 4
            For cnt = 1 To nRows
                '移动到前面的4个字节之后,提取相应数据,
                '并将其转换为IPAddrRow类型
                CopyMemory IPAddrRow, buff(4 + (cnt - 1) * nStructSize), nStructSize
                '将结果填写到列表视中
                With IPAddrRow
                    Set itmx = LvwIpTable.ListItems.Add(, , GetInetStrFromPtr(.dwIndex))
                    itmx.SubItems(1) = GetInetStrFromPtr(.dwAddr)
                    itmx.SubItems(2) = GetInetStrFromPtr(.dwMask)
                    itmx.SubItems(3) = GetInetStrFromPtr(.dwBCastAddr)
                    itmx.SubItems(4) = GetInetStrFromPtr(.dwReasmSize)
                    itmx.SubItems(5) = (.unused1)
                    itmx.SubItems(6) = (.unused2)
                End With
            Next cnt
        End If
    End If
End Sub

Private Sub Form_Load()
    With LvwIpTable
        .View = lvwReport
        .ColumnHeaders.Add , , "索引"
        .ColumnHeaders.Add , , "IP地址"
        .ColumnHeaders.Add , , "子网掩码"
        .ColumnHeaders.Add , , "广播地址"
        .ColumnHeaders.Add , , "大小"
        .ColumnHeaders.Add , , "保留字段1"
        .ColumnHeaders.Add , , "保留字段2"
    End With
End Sub
Private Function GetInetStrFromPtr(ByVal Address As Long) As String
    GetInetStrFromPtr = GetStrFromPtrA(inet_ntoa(Address))
End Function

Private Function GetStrFromPtrA(ByVal lpszA As Long) As String
    GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
    Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -