前段时间,搞个小程序要用到,就综合网上的自己改写了一段,很简单,自己看看吧。
生效范围只有在局域网中,原因很简单,因为在广域网上是无法获知远端的MAC地址的,因为在数据包中的数据链路层包含的只是近端路由器的MAC地址,而你的数据包在互联网上传播,早经过了无数路由器,最后到达你这里的数据包中,只含有最后一个路由器的MAC地址,也就是离你最近的那台路由器。
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 CopyMemory1 Lib "kernel32" Alias "RtlMoveMemory" (dst As Any, src As Any, ByVal bcount As Long) Public Function GetRemoteMACAddress(ByVal sRemoteIP As String) As String 'VB 获取局域网中指定IP地址的 Mac 地址 Dim dwRemoteIP As Long, pMacAddr As Long, bpMacAddr() As Byte, PhyAddrLen As Long, cnt As Long, tmp As String dwRemoteIP = inet_addr(sRemoteIP) If dwRemoteIP 0 Then PhyAddrLen = 6 'On Error Resume Next If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = 0 Then If pMacAddr 0 And PhyAddrLen 0 Then ReDim bpMacAddr(0 To PhyAddrLen - 1) CopyMemory1 bpMacAddr(0), pMacAddr, ByVal PhyAddrLen For cnt = 0 To PhyAddrLen - 1 If bpMacAddr(cnt) = 0 Then tmp = tmp & "00-" Else If Len(Hex$(bpMacAddr(cnt))) = 1 Then tmp = tmp & "0" & Hex$(bpMacAddr(cnt)) & "-" Else tmp = tmp & Hex$(bpMacAddr(cnt)) & "-" End If End If Next If Len(tmp) > 0 Then GetRemoteMACAddress = Left$(tmp, Len(tmp) - 1) End If Exit Function Else GetRemoteMACAddress = "00-00-00-00-00-00" End If Else GetRemoteMACAddress = "00-00-00-00-00-00" End If 'SendARP Else GetRemoteMACAddress = "00-00-00-00-00-00" End If 'dwRemoteIP End Function
文章来源于lcx.cc:VB 获取局域网中指定IP地址的 Mac 地址
相关推荐: 美国政府入侵中国网络多年,透过入侵巨型路由器,一举入侵成千上万电脑
6月13日讯 针对揭露美国政府监控人民的斯诺登爆料,美国政府随时可以读取任何人的电邮,让包括谷歌在内的网络公司巨头致函美国政府自清等事件,与他最新爆料,美国政府已入侵中国大陆与香港特区的网络多年,白宫在12号都以调查仍在进行为由,选择不予回应。 斯诺登再爆料,…
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论