如何获得网卡号,知IP

sxzqlzx 2003-05-30 09:50:20
局域网内如何获得网卡号,知IP
...全文
81 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
newhuai 2003-06-02
  • 打赏
  • 举报
回复
这个问题太简单了,在你知道对方的IP地址的前提之下,你可以用C++BUILE50调用win系统下的一个命令呀就可以了,即就是这个命令呀nbtstat -a *.*.*.* 就ok!!!!!
jxhywdh 2003-06-02
  • 打赏
  • 举报
回复
上面 的程序我无法编译!!!
[C++ Error] Unit1.cpp(22): E2451 Undefined symbol 'IPAddr'
[C++ Error] Unit1.cpp(26): E2268 Call to undefined function 'inet_addr'
[C++ Error] Unit1.cpp(30): E2268 Call to undefined function 'SendARP'
不知道要加什么头文件????
sczyq 2003-06-02
  • 打赏
  • 举报
回复
好象我以前回答过同样问题,查找一下“MAC”
fly_hyp 2003-06-01
  • 打赏
  • 举报
回复
不用这样的。netbios有专用函数的。
小笨象 2003-06-01
  • 打赏
  • 举报
回复
最好不要用netbios ,因为有些系统不一定安装了netbios,所以还是应该用sdk。
ybluo 2003-05-30
  • 打赏
  • 举报
回复

Platform SDK: Internet Protocol Helper
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 an array of ULONG variables. The first six bytes of this array receive 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.

Remarks
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.

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 ("216.145.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
Windows NT/2000/XP: Included in Windows 2000; Windows XP Pro; and Windows .NET Server.
Windows 95/98/Me: Unsupported.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.

See Also
CreateIpNetEntry, DeleteIpNetEntry, FlushIpNetTable, SetIpNetEntry

Platform SDK Release: August 2001 What did you think of this topic?
Let us know. Order a Platform SDK CD Online
(U.S/Canada) (International)



Requirements
Windows NT/2000/XP: Included in Windows 2000; Windows XP Pro; and Windows .NET Server.
Windows 95/98/Me: Unsupported.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.
See Also
CreateIpNetEntry, DeleteIpNetEntry, FlushIpNetTable, SetIpNetEntry
ITBlueCollar 2003-05-30
  • 打赏
  • 举报
回复
arp

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧