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

📄 form1.frm

📁 电子书“Visual Basic 6 网络编程实例教程.rar”
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "网卡的IP地址"
   ClientHeight    =   1395
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4770
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1395
   ScaleWidth      =   4770
   StartUpPosition =   2  '屏幕中心
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   480
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   480
      Width           =   2655
   End
   Begin VB.CommandButton Command1 
      Caption         =   "运行(&R)"
      Height          =   375
      Left            =   3360
      TabIndex        =   0
      Top             =   480
      Width           =   1095
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "网卡IP地址:"
      Height          =   180
      Left            =   480
      TabIndex        =   2
      Top             =   240
      Width           =   1080
   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 Command1_Click()
     '传递地址列表中分隔各IP地址的界定字符"+"号
   Text1.Text = LocalIPAddresses("+")
End Sub

Private Function LocalIPAddresses(ByVal sDelim As String) As String
   
   Dim cbRequired  As Long
   Dim buff()      As Byte
   Dim Adapter     As IP_ADAPTER_INFO
   Dim AdapterStr  As IP_ADDR_STRING
   Dim ptr1        As Long
   Dim sIPAddr     As String
   Dim sAllAddr    As String
   Call GetAdaptersInfo(ByVal 0&, cbRequired)
   If cbRequired > 0 Then
      ReDim buff(0 To cbRequired - 1) As Byte
      If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then
        '获取存放数据的缓存buff()的指针
         ptr1 = VarPtr(buff(0))
        '如果没有网卡,则ptr1为0
         Do While (ptr1 <> 0)
           '复制缓存中的第一个网卡的数据到IP_ADAPTER_INFO结构中
            CopyMemory Adapter, ByVal ptr1, LenB(Adapter)
            With Adapter
              'IpAddress.IpAddr成员给出了网卡的IP地址
               sIPAddr = TrimNull(StrConv(.IpAddressList.IpAddress.IpAddr, vbUnicode))
               sAllAddr = sAllAddr & sIPAddr & "+"
               ptr1 = .dwNext
            End With  'With Adapter
         Loop  'Do While (ptr1 <> 0)
      End If  'If GetAdaptersInfo
   End If  'If cbRequired > 0
  '删除最后的界定字符
   If Len(sAllAddr) > 0 Then
      sAllAddr = Left$(sAllAddr, Len(sAllAddr) - 1)
   End If
  '返回地址字符串
   LocalIPAddresses = sAllAddr
End Function

Private Function TrimNull(item As String)
    Dim pos As Integer
    pos = InStr(item, Chr$(0))
    If pos Then
          TrimNull = Left$(item, pos - 1)
    Else: TrimNull = item
    End If
End Function

⌨️ 快捷键说明

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