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

📄 form1.frm

📁 由IP地址获取MAC地址!(非ping)通常可以用来测试局域内有多少台计算机!
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1455
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   2715
   LinkTopic       =   "Form1"
   ScaleHeight     =   1455
   ScaleWidth      =   2715
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text2 
      Height          =   270
      Left            =   120
      TabIndex        =   2
      Text            =   "Text2"
      Top             =   480
      Width           =   2415
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   120
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   120
      Width           =   2415
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   840
      Width           =   2415
   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 Const NO_ERROR = 0
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Long
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Long, ByVal SrcIP As Long, pMacAddr As Long, PhyAddrLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal bcount As Long)
    
Private Sub form_Load()
    Text1.Text = "192.168.1.68"
    Text2.Text = ""
    Command1.Caption = "获取MAC"
End Sub

Private Sub Command1_Click()
    Dim sRemoteMacAddress   As String
    If Len(Text1.Text) > 0 Then
        If GetRemoteMACAddress(Text1.Text, sRemoteMacAddress) = True Then
            Text2.Text = sRemoteMacAddress
        Else
            Text2.Text = "找不到此计算机!"
        End If
    End If
End Sub

'功能   通过IP地址,获取MAC地址!
'参数   sRemoteIP:IP地址;
'       sRemoteMacAddress: MCA地址
'       返回:成功与否
Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, sRemoteMacAddress As String) As Boolean
    Dim dwRemoteIP As Long
    Dim pMacAddr As Long
    Dim bpMacAddr() As Byte
    Dim PhyAddrLen As Long
    Dim cnt As Long
    Dim tmp As String
    GetRemoteMACAddress = False
    dwRemoteIP = inet_addr(sRemoteIP)
    If dwRemoteIP <> 0 Then
        PhyAddrLen = 6
        If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
            If pMacAddr <> 0 And PhyAddrLen <> 0 Then
                ReDim bpMacAddr(0 To PhyAddrLen - 1)
                CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
                For cnt = 0 To PhyAddrLen - 1
                    If bpMacAddr(cnt) = 0 Then
                        tmp = tmp & "00-"
                    ElseIf bpMacAddr(cnt) < 16 Then
                        tmp = tmp & "0" & Hex$(bpMacAddr(cnt)) & "-"
                    Else
                        tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
                    End If
                Next
                If Len(tmp) > 0 Then
                    sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
                    GetRemoteMACAddress = True
                End If
            End If
        End If
    End If
End Function


⌨️ 快捷键说明

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