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;
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.
VC可以实现,借助于WPCap,呵呵,不然在windows 4.x里是不行的,windows 5.x容易一些,好像:-)
更正:
WPCap -> WinPCap
还有WinPCap怎么用啊,望能给我解释一下,如有类似的例子那就感激不尽了
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.
可以到http://winpcap.polito.it/去下载开发包,还有示例程序。
小弟没用过这个WinpCap这个东东,这个东西需要安装吗?但愿最好不用安装的,
看上面的msdn上的解说sendArp应该是知道目的ip地址,用来获取对应的mac地址的,我的要求刚好和这相反,我是知道mac地址想获取对应的ip地址,有没有诸如sendRarp之类的API函数?To:baoch110(来自北方的包子)
你的投机取巧能解释一下吗,多谢!