急!!winpcap编程中如何用获得指定网卡的MAC

lingducool 2011-11-16 10:14:22
我现在需要知道我在截包前算中的网卡的mac地址,如何才能做到。我在网上查到的一些方法是通过发送NCBENUM命令获取网卡的数目和每个网卡的内部编号,然后对每个网卡标号发送NCBASTAT命令获取其MAC地址,但是我不知道我所选中的网卡的标号是多少。。我的winpcap截包的编程中,选中的网卡信息都在pcap_if结构中,如何获得其标号????或者说怎么才能获得制定网卡的mac?
...全文
218 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gloveing 2011-11-16
  • 打赏
  • 举报
回复
pcap_if结构:(没有MAC信息)
pcap_if * next
if not NULL, a pointer to the next element in the list; NULL for the last element of the list

char * name
a pointer to a string giving a name for the device to pass to pcap_open_live()

char * description
if not NULL, a pointer to a string giving a human-readable description of the device

pcap_addr * addresses
a pointer to the first element of a list of addresses for the interface

u_int flags
PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK, that is set if the interface is a loopback interface.
Gloveing 2011-11-16
  • 打赏
  • 举报
回复
#include "winsock.h" 
#include <stdio.h>
#include <iphlpapi.h>
#pragma comment(lib,"iphlpapi.lib")
void main()
{
IP_ADAPTER_INFO Interface[20];
PIP_ADAPTER_INFO NetInterface = NULL;
DWORD Result = 0;
unsigned long Length = sizeof(Interface);
Result = GetAdaptersInfo(Interface, &Length);
if (Result != NO_ERROR)
{
printf("GetAdaptersInfo failed error.\n");
}
else
{
NetInterface = Interface;
while (NetInterface)
{
static int number;
number++;
printf("第%d个网络接口信息:\n", number);
printf("名称:%s\n", NetInterface->AdapterName);
printf("信息:%s\n", NetInterface->Description);
printf("地址:%ld\n", NetInterface->Address);
printf("MAC地址:%02X:%02X:%02X:%02X:%02X:%02X\n", NetInterface->Address[0], NetInterface->Address[1], NetInterface->Address[2], NetInterface->Address[3], NetInterface->Address[4], NetInterface->Address[5]);
printf("IP地址:%s\n", NetInterface->IpAddressList.IpAddress.String);
printf("IP地址掩码:%s\n", NetInterface->IpAddressList.IpMask.String);
printf("网关:%s\n", NetInterface->GatewayList.IpAddress.String);
if (NetInterface->DhcpEnabled)
{
printf("DHCP配置:\n");
printf("服务器:%s\n", NetInterface->DhcpServer.IpAddress.String);
printf("租用:%ld\n", NetInterface->LeaseObtained);
}
else
printf("无DHCP配置\n");
if (NetInterface->HaveWins)
{
printf("Wins配置:\n");
printf("主Wins服务器:%s\n", NetInterface->PrimaryWinsServer.IpAddress.String);
printf("次Wins服务器:%s\n", NetInterface->SecondaryWinsServer.IpAddress.String);
}
else
printf("无服务器配置\n");
NetInterface = NetInterface->Next;
}
}
}

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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