我有一段程序可供参考:这是我自己写的!!服务器端获取远程机的MAC程序:
'-----BEGIN iphlpapi Function-----'DWORDPrivate Declare Function SendARP Lib "iphlpapi.dll" _
        (ByVal DestIP As Long, _
        ByVal SrcIP As Long, _
        pMacAddr As Long, _
        PhyAddrLen As Long) As Long'    IPAddr DestIP,
'    IPAddr SrcIP,
'    PULONG pMacAddr,
'    PULONG  PhyAddrLen'-----END iphlpapi Function-----'-----BEGIN WinSocket2 Function-----Private Declare Function inet_addr Lib "ws2_32.dll" _
    (ByVal cp As Long) As Long
    
'-----END WinSocket2 Function-----Private Const NO_ERROR = 0 '  dderror'-----BEGIN System Function-----Private Declare Sub CopyMemory Lib "kernel32" Alias _
        "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As _
        Long, ByVal cbCopy As Long)
        
Private Declare Function lstrlen Lib "kernel32" Alias _
        "lstrlenA" (ByVal lpString As String) As Long
        Private Declare Function FormatMessage Lib "kernel32" Alias _
        "FormatMessageA" (ByVal dwFlags As Long, _
                          lpSource As Any, _
                          ByVal dwMessageId As Long, _
                          ByVal dwLanguageId As Long, _
                          ByVal lpBuffer As String, _
                          ByVal nSize As Long, _
                          Arguments As Long) As LongPrivate Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200Private Declare Function GetSystemDefaultLangID _
                    Lib "kernel32" () As Integer
                    
                    
'-----END System Function-----Public Function GetRemoteMac(StrMac As String, _
                            StrErr As String, _
                            ByVal StrDesIP As String, _
                            Optional StrSrcIP As String = "") As Long
'************************************************************************
'函数功能:返回对方的MAC
'参数:StrMac(返回值)对方的MAC
'      StrErr(返回值)错误信息,不成功时返回
'      StrDesIP(输入参数)对方的IP地址 (数据类型:IPFormat)
'      StrSrcIP(输入参数)本地路由IP地址(数据类型:IPFormat)(可选)
'数据类型:IPFormat:任何有效形式的IP地址字串,如:10.40.50.1 或 010.040.050.001
'      或: 10.4D.5F.01
'函数返回:错误号,如果成功,0,否则,非0
'************************************************************************Dim lngDesIP As Long
Dim LngSrcIP As LongDim lngDesIPLen As Long
Dim LngSrcIPLen As LongDim lpszStrDesIP As Long
Dim lpszStrSrcIP As LongDim lngDesIPb() As Byte
Dim LngSrcIPb() As Byte
    
'先置成功的返回值
GetRemoteMac = 0'将传入的IP地址字串转换为字串指针
If Len(StrDesIP) <> 0 Then
    lngDesIPLen = BSTRtoLPSTR(StrDesIP, lngDesIPb, lpszStrDesIP)
Else
    StrErr = "参数:StrMac,目标IP地址不可以为空串!"
    GetRemoteMac = 9998
    Exit Function
End IfIf Len(StrSrcIP) <> 0 Then
    LngSrcIPLen = BSTRtoLPSTR(StrSrcIP, LngSrcIPb, lpszStrSrcIP)
End If'将字串的指针传入 转换IP为Long
lngDesIP = inet_addr(lpszStrDesIP)'如果转换错误
If lngDesIP = -1 Then
    StrErr = "参数:StrMac,目标IP地址不是有效地址!"
    GetRemoteMac = 9999
    Exit Function
End IfIf Len(StrSrcIP) <> 0 Then
    LngSrcIP = inet_addr(lpszStrSrcIP)
    '忽略本地路由IP转换错误
    If LngSrcIP = -1 Then
        LngSrcIP = 0
    End If
Else
    LngSrcIP = 0
End If
    
Dim StrMacAddr As StringDim lpszMacAddr As Long
Dim lngMacAddrb() As Byte
Dim lngPhyAddrLen As LongDim retValue As Long'为变量分配内存:
StrMacAddr = String(6, Chr(0))  
lngPhyAddrLen = BSTRtoLPSTR(StrMacAddr, lngMacAddrb, lpszMacAddr)
'用Byval取BSTR字串地址中的值
retValue = SendARP(lngDesIP, LngSrcIP, ByVal lpszMacAddr, lngPhyAddrLen)
Dim ErrBuffer As StringDim lpszErrBuffer As Long
Dim lngErrBufferb() As Byte
Dim lngErrBufferLen As Long
'如果成功
If retValue = NO_ERROR Then
    
    '转换为字串
    StrMacAddr = BytePhyStrToHex(lngMacAddrb)
    
    StrMac = StrMacAddr
    
'如果失败
Else
    '为变量分配内存:
    ErrBuffer = String(128, Chr(0))
    
    lngErrBufferLen = BSTRtoLPSTR(ErrBuffer, lngErrBufferb, lpszErrBuffer)    '查询出错信息
    FormatMessage _
        FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, _
        Null, _
        retValue, _
        GetSystemDefaultLangID, _
        ByVal lpszErrBuffer, _
        lngErrBufferLen, _
        0
    '返回出错信息
    
    StrErr = LPSTRtoBSTR(lpszErrBuffer)
    If Len(StrErr) = 0 Then
        Select Case retValue
        Case 31
            StrErr = "目标IP无法连接!"
        Case Else
            StrErr = "无法获取错误信息!"
        End Select
    End If
    GetRemoteMac = retValue
End IfEnd Function
Private Function BSTRtoLPSTR(sBSTR As String, b() As Byte, lpsz As Long) As Long' Input: a nonempty BSTR string
' Input: **undimensioned** byte array b()
' Output: Fills byte array b() with ANSI char string
' Output: Fills lpsz with a pointer to b() array
' Returns byte count, not including terminating null
' Original BSTR is not affectedDim cBytes As Long
Dim sABSTR As StringcBytes = LenB(sBSTR)' ReDim array, with space for terminating null
ReDim b(1 To cBytes + 2) As Byte' Convert to ANSI
sABSTR = StrConv(sBSTR, vbFromUnicode)' Point to BSTR char array
lpsz = StrPtr(sABSTR)' Copy the array
CopyMemory b(1), ByVal lpsz, cBytes + 2' Point lpsz to new array
lpsz = VarPtr(b(1))' Return byte count
BSTRtoLPSTR = cBytesEnd FunctionPrivate Function BytePhyStrToHex(BytePhyStr() As Byte) As String'Input:Byte array of MAC
'Output:Hex string of MACDim TempStr As String
Dim TempByteStr As String
Dim i As Integer'The MAC Length only is 6 bytes, so we only get first 6 bytes.For i = 1 To 6
    TempByteStr = Hex(BytePhyStr(i))
    If Len(TempByteStr) = 1 Then
        TempByteStr = "0" & TempByteStr
    End If
    TempStr = TempStr & TempByteStr
Next iBytePhyStrToHex = TempStrEnd FunctionPrivate Function LPSTRtoBSTR(ByVal lpsz As Long) As String' Input: a valid LPSTR pointer lpsz
' Output: a sBSTR with the same character arrayDim cChars As Long' Get number of characters in lpsz
cChars = lstrlen(lpsz)' Initialize string
LPSTRtoBSTR = String$(cChars, 0)' Copy string
CopyMemory ByVal StrPtr(LPSTRtoBSTR), ByVal lpsz, cChars' Convert to Unicode
LPSTRtoBSTR = Trim0(StrConv(LPSTRtoBSTR, vbUnicode))End FunctionPrivate Function Trim0(sName As String) As String
  ' Right trim string at first null.
  Dim x As Integer
  x = InStr(sName, vbNullChar)
  If x > 0 Then Trim0 = Left$(sName, x - 1) Else Trim0 = sName
End Function
 
回复人: dbcontrols(泰山) (2002-1-17 8:34:37)  得0分 
这种代码在很多网站都多的是,大家未必用到.给大家推荐几个网站到是必要的.如果你的E文过关,可以到很多国外网站去找你需要的,不需要的立即删除,没任何用的东西也叫"垃圾"  

解决方案 »

  1.   

    这个原放在
    http://www.csdn.net/expert/topic/480/480915.shtm
    上面是高手的回复!
      

  2.   

    原来还有SENDARP这等API的啊,我原来一直用NETBIOS来着,但这只是取远端主机的MAC地址,但是取来以后如果不合用,想修改本机上的ARP缓存里面的ARP映射怎么办?
    另:这些ARP是从哪里看来的啊,真是不错
      

  3.   

    我就是用SDK,自己改写!你自己也查帮助吧!这会对你帮助很大的!
      

  4.   

    呵呵,BARDO,我通过IPHLPAPI找到两个函数
    DeleteIpNetEntry
    The DeleteIpNetEntry function deletes an ARP entry from the ARP table on the local computer.和CreateIpNetEntry
    The CreateIpNetEntry function creates an Address Resolution Protocol (ARP) entry in the ARP table on the local computer.可能就是这样的吧