SendARP The SendARP function sends an ARP request to obtain the physical address that corresponds to the specified destination IP address.DWORD SendARP( IPAddr DestIP, // destination IP address IPAddr SrcIP, // IP address of sender PULONG pMacAddr, // returned physical address PULONG PhyAddrLen // length of returned physical addr. ); Parameters DestIP [in] Specifies the destination IP address. The ARP request attempts to obtain the physical address that corresponds to this IP address. SrcIP [in] Specifies the IP address of the sender. This parameter is optional. The caller may specify zero for the parameter. pMacAddr [out] Pointer to a ULONG variable. This variable receives the physical address that corresponds to the IP address specified by the DestIP parameter. PhyAddrLen [out] Pointer to a ULONG variable. This variable contains the length of the physical address pointed to by the pMacAddr parameter. 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 Win32 Simple Data Types. To convert an IP address between dotted decimal notation and IPAddr format, use the inet_addr and inet_ntoa functions.Requirements Windows NT/2000 or later: Requires Windows 2000 or later. Windows 95/98/Me: Unsupported. Header: Declared in Iphlpapi.h. Library: Use Iphlpapi.lib.
/////////////////////////////////////
回复人: Frank_Xu() ( ) 信誉:100 2002-3-17 10:55:30 得分:50
包含#include <Nb30.h>
加載Netapi32.lib (Projects>>Setting>>Object/Library Modules)
CString GetMacAddress(CString sNetBiosName/*網絡上的電腦名稱*/)
{
ASTAT Adapter;
NCB ncb;
UCHAR uRetCode;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0;
uRetCode = Netbios(&ncb);
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;
sNetBiosName.MakeUpper();
FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20);
strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);
ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20;
ncb.ncb_callname[NCBNAMSZ] = 0x0;
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&ncb);
CString sMacAddress;
if (uRetCode == 0)
{
sMacAddress.Format(_T("%02X-%02X-%02X-%02X-%02X-%02X"),
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5]);
}
return sMacAddress;
}
The SendARP function sends an ARP request to obtain the physical address that corresponds to the specified destination IP address.DWORD SendARP(
IPAddr DestIP, // destination IP address
IPAddr SrcIP, // IP address of sender
PULONG pMacAddr, // returned physical address
PULONG PhyAddrLen // length of returned physical addr.
);
Parameters
DestIP
[in] Specifies the destination IP address. The ARP request attempts to obtain the physical address that corresponds to this IP address.
SrcIP
[in] Specifies the IP address of the sender. This parameter is optional. The caller may specify zero for the parameter.
pMacAddr
[out] Pointer to a ULONG variable. This variable receives the physical address that corresponds to the IP address specified by the DestIP parameter.
PhyAddrLen
[out] Pointer to a ULONG variable. This variable contains the length of the physical address pointed to by the pMacAddr parameter.
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 Win32 Simple Data Types. To convert an IP address between dotted decimal notation and IPAddr format, use the inet_addr and inet_ntoa functions.Requirements
Windows NT/2000 or later: Requires Windows 2000 or later.
Windows 95/98/Me: Unsupported.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.