问题如题,各位大虾,怎么用vc实现阿,我在网上找了好几次都没有什么收获,只知道可以发送RARP报文可以实现,但不知道如何写?还有就是这种方法是不是不能在跨网段时不能实现?
请各位大虾帮帮小弟,完不成任务,就不能回家过春节了,谢谢了!

解决方案 »

  1.   

    跨网段不行
    VC可以实现,借助于WPCap,呵呵,不然在windows 4.x里是不行的,windows 5.x容易一些,好像:-)
      

  2.   

    sorry,沿袭了别人的坏习惯:-)
    更正:
    WPCap -> WinPCap
      

  3.   

    有个投机取巧的办法,^_^如果是一个网段内的,可以用sendarp函数得到所有网段内所有mac地址,具体看msdn,然后和你手中的mac地址比较,可以知道那个ip对那个mac了!!!
      

  4.   

    老大,可能是我的msdn版本比较老,我的msdn中没有sendarp的解说,找不到这个函数,请您给我讲一下好吗?或者把msdn中的解说贴一下。
    还有WinPCap怎么用啊,望能给我解释一下,如有类似的例子那就感激不尽了
      

  5.   

    winpCap就是windows packet capture,一个第三方的工具。
    sendarp我也不太懂,把msdn的内容给你贴出来
    The SendARP function sends an ARP request to obtain the physical address that corresponds to the specified destination IP address.
    DWORD SendARP(
      IPAddr DestIP,
      IPAddr SrcIP,
      PULONG pMacAddr,
      PULONG PhyAddrLen
    );Parameters
    DestIP 
    [in] Destination IP address. The ARP request attempts to obtain the physical address that corresponds to this IP address. 
    SrcIP 
    [in] IP address of the sender. This parameter is optional. The caller may specify zero for the parameter. 
    pMacAddr 
    [out] Pointer to an array of ULONG variables. The first six bytes of this array receive the physical address that corresponds to the IP address specified by DestIP. 
    PhyAddrLen 
    [in, out] On input, specifies the maximum buffer size the user has set aside at pMacAddr to receive the MAC address, in bytes. On output, specifies the number of bytes written to pMacAddr. 
    Return Values
    If the function succeeds, the return value is NO_ERROR.If the function fails, use FormatMessage to obtain the message string for the returned error.Res
    For information about the IPAddr data type, see Windows Simple Data Types. To convert an IP address between dotted decimal notation and IPAddr format, use the inet_addr and inet_ntoa functions.Example Code 
    The following code demonstrates how to obtain the media access control (MAC) address associated with a specified IP address.//
    // Link with ws2_32.lib and iphlpapi.lib
    //#include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    #include <iphlpapi.h>
    int __cdecl main()
    {
        HRESULT hr;
        IPAddr  ipAddr;
        ULONG   pulMac[2];
        ULONG   ulLen;    ipAddr = inet_addr ("192.168.25.31");
        memset (pulMac, 0xff, sizeof (pulMac));
        ulLen = 6;
        
        hr = SendARP (ipAddr, 0, pulMac, &ulLen);
        printf ("Return %08x, length %8d\n", hr, ulLen);
        
        size_t i, j;
        char * szMac = new char[ulLen*3];
        PBYTE pbHexMac = (PBYTE) pulMac;    //
        // Convert the binary MAC address into human-readable
        //
        for (i = 0, j = 0; i < ulLen - 1; ++i) {
            j += sprintf (szMac + j, "%02X:", pbHexMac[i]);
        }
        
        sprintf (szMac + j, "%02X", pbHexMac[i]);
        printf ("MAC address %s\n", szMac);
        
        delete [] szMac;    return 0;
    }
    Requirements
    Client: Included in Windows XP and Windows 2000 Professional.
    Server: Included in Windows Server 2003 and Windows 2000 Server.
    Header: Declared in Iphlpapi.h.
    Library: Use Iphlpapi.lib.
      

  6.   

    还有WinpCap很好用,功能也非常强大
    可以到http://winpcap.polito.it/去下载开发包,还有示例程序。
      

  7.   

    多谢各位相助!
    小弟没用过这个WinpCap这个东东,这个东西需要安装吗?但愿最好不用安装的,
    看上面的msdn上的解说sendArp应该是知道目的ip地址,用来获取对应的mac地址的,我的要求刚好和这相反,我是知道mac地址想获取对应的ip地址,有没有诸如sendRarp之类的API函数?To:baoch110(来自北方的包子)
    你的投机取巧能解释一下吗,多谢!
      

  8.   

    SendARP在windows 4.x不会work的
      

  9.   

    大哥们帮帮忙 阿,小弟解决不了问题要回不了家了,请各位大虾指点,给详细的讲一下,如果利用发送rarp报文,最好能是通过底层的发送,就像通过利用socket发送icmp报文,谢谢!