?? form1.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 + -