#include "stdafx.h"
#include <pcap.h>
#include <string.h>
#include <stdio.h>
#include <remote-ext.h>
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include<atlbase.h>
#include<atlconv.h>
#include"iphlpapi.h"
#include <Iprtrmib.h>
#include <Iptypes.h>
#pragma comment(lib,"Iphlpapi.lib")
#pragma comment(lib,"WS2_32.LIB")
#pragma comment(lib,"mswsock.lib")
#pragma comment(lib,"wpcap.lib")
#pragma comment(lib,"netapi32.lib")
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter=NULL;
char *PinfoIP,*PpcapIP;
void main( )
{
/********************************获取mac********************************/
DWORD dwRetVal=0;
pAdapterInfo=(IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO));
ULONG ulOutBufLen=sizeof(IP_ADAPTER_INFO);
if(GetAdaptersInfo(pAdapterInfo,&ulOutBufLen)!=ERROR_SUCCESS)
{
GlobalFree(pAdapterInfo);
pAdapterInfo=(IP_ADAPTER_INFO*)malloc(ulOutBufLen);
}
if((dwRetVal=GetAdaptersInfo(pAdapterInfo,&ulOutBufLen))==NO_ERROR)
{
pAdapter=pAdapterInfo;
while(pAdapter)
{
if(pAdapter->Type==MIB_IF_TYPE_ETHERNET)
{
printf("\tAdapter Name:\t%s\n",pAdapter->AdapterName);
printf("\tAdapterName description:\t%s\n",pAdapter->Description);
printf("\tAdapterName MAC:");
printf("\t");
for(int i=0;i<pAdapter->AddressLength;i++)
{
printf("%02X%c",pAdapter->Address[i],
i==pAdapter->AddressLength-1?'\n':'-');
}
printf("\tIPAddress:\t%s\n",pAdapter->IpAddressList.IpAddress.String);
PinfoIP=pAdapter->IpAddressList.IpAddress.String;
}
pAdapter=pAdapter->Next;
}
}
else
return;
/***************************获取mac结束***********************************/
printf("以下通过winpcap获取\n\n\n\n");
/**************************我是淫荡分割线****************************/
pcap_if_t *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
return;
}
/********************** 获取网卡列表******************************/
/********************** 选择网卡******************************/
for (d = alldevs; d!=NULL; d = d->next)
{
printf("\tAdapter name:\t%s\n",d->name);
if(d->description)
{
printf("\tAdapterName description:\t%s\n",d->description);
}
if(d->addresses)
{
struct sockaddr_in *paddr;
paddr=(struct sockaddr_in *)d->addresses->addr;
printf("\tAdapter IP:\t%s\n",inet_ntoa(paddr->sin_addr));
PpcapIP=inet_ntoa(paddr->sin_addr);
}
}
/********************** 选择网卡结束******************************/
if(PinfoIP==PpcapIP)
printf("\n一样");
else
printf("\n不一样");
printf("\nPinfoIP长度:%d",strlen(PinfoIP));
printf("\nPpcapIP长度:%d",strlen(PpcapIP));
int i=0;
bool flag=true;
while(i<strlen(PpcapIP))
{
if(PinfoIP[i]!=PpcapIP[i])
flag=!flag;
i++;
}
printf("\n是否一样:%d,比较长度:%d\n",flag,i);
}}