MAC Address kepanjangan dari Media Access Control Address
atau bisa disebut nomor seri unik yang terpasang di kartu jaringan.
1. Buat 1 project dengan 1 Form
2. Tambahkan 1 Commanbutton(name=CmdGetMAC,caption=Get MAC address)
3. Tambahkan 2 Label, label1(Caption=IP Address Tujuan) dan label2(name=LblMAC)
4. Tambahkan 1 Textbox(name=TxtIPAddress)
Copy coding dibawah ini dan paste di Editor Form:
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 ScrIP As Long, _
pMacAdd As Long, PhyAddrLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (dst As Any, scr As Any, _
ByVal bcount As Long)
Private Sub CmdGetMAC_Click()
Dim sRemoteMacAddress As String
If Len(TxtIPAddress.Text) > 0 Then
If GetRemoteMACAddress(TxtIPAddress.Text = _
sRemoteMacAddress) Then
LblMAC.Caption = sRemoteMacAddress
Else
LblMAC.Caption = "(SendARP call failed)"
End If
End If
End Sub
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
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-"
Else
tmp = tmp & Hex$(bpMacAddr(cnt)) & " "
End If
Next
If Len(tmp) > 0 Then
sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
GetRemoteMACAddress = True
End If
Exit Function
Else
GetRemoteMACAddress = False
End If
Else
GetRemoteMACAddress = False
End If
Else
GetRemoteMACAddress = False
End If
End Function
2 komentar:
kodenya failed tuh berada tolong perbaiki lagi
scroce codenya failed tuh berada saya mengunakan visaul basic vb6 portabel
mahon pencerahannya
Posting Komentar