关键字:WinPcap 网卡 MAC地址

作者:txw1958

在WpdPack_4_1_2\WpdPack\Examples-remote\PacketDriver\GetMacAddress\目录下有获取MAC地址源文件

GetMacAddress.c

  1: /* 
  2:  * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy) 
  3:  * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California) 
  4:  * All rights reserved. 
  5:  * 
  6:  * Redistribution and use in source and binary forms, with or without 
  7:  * modification, are permitted provided that the following conditions 
  8:  * are met: 
  9:  * 
 10:  * 1. Redistributions of source code must retain the above copyright 
 11:  * notice, this list of conditions and the following disclaimer. 
 12:  * 2. Redistributions in binary form must reproduce the above copyright 
 13:  * notice, this list of conditions and the following disclaimer in the 
 14:  * documentation and/or other materials provided with the distribution. 
 15:  * 3. Neither the name of the Politecnico di Torino, CACE Technologies  
 16:  * nor the names of its contributors may be used to endorse or promote  
 17:  * products derived from this software without specific prior written  
 18:  * permission. 
 19:  * 
 20:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21:  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 23:  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 24:  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 25:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 26:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 30:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 31:  * 
 32:  */ 
 33:  
 34: #include <stdio.h> 
 35: #include <conio.h> 
 36: #include "..\..\..\Include\packet32.h" 
 37: #include "..\..\..\Include\ntddndis.h"   
 38: #define Max_Num_Adapter 10 
 39: char        AdapterList[Max_Num_Adapter][1024]; 
 40:  
 41: int main() 
 42: { 
 43:     LPADAPTER    lpAdapter = 0; 
 44:     int            i; 
 45:     DWORD        dwErrorCode; 
 46:     char        AdapterName[8192]; 
 47:     char        *temp,*temp1; 
 48:     int            AdapterNum=0,Open; 
 49:     ULONG        AdapterLength; 
 50:     PPACKET_OID_DATA  OidData; 
 51:     BOOLEAN        Status; 
 52:      
 53:     // 
 54:     // Obtain the name of the adapters installed on this machine 
 55:     // 
 56:  
 57:     printf("Packet.dll test application. Library version:%s\n", PacketGetVersion()); 
 58:      
 59:     printf("Adapters installed:\n"); 
 60:     i=0;     
 61:      
 62:     AdapterLength = sizeof(AdapterName); 
 63:      
 64:     if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){ 
 65:         printf("Unable to retrieve the list of the adapters!\n"); 
 66:         return -1; 
 67:     } 
 68:     temp=AdapterName; 
 69:     temp1=AdapterName; 
 70:  
 71:     while ((*temp!='\0')||(*(temp-1)!='\0')) 
 72:     { 
 73:         if (*temp=='\0')  
 74:         { 
 75:             memcpy(AdapterList[i],temp1,temp-temp1); 
 76:             temp1=temp+1; 
 77:             i++; 
 78:         } 
 79:         temp++; 
 80:     } 
 81:            
 82:     AdapterNum=i; 
 83:     for (i=0;i<AdapterNum;i++) 
 84:         printf("\n%d- %s\n",i+1,AdapterList[i]); 
 85:     printf("\n"); 
 86:  
 87:  
 88:     do  
 89:     { 
 90:         printf("Select the number of the adapter to open : "); 
 91:         scanf("%d",&Open); 
 92:         if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum);  
 93:     } while (Open>AdapterNum); 
 94:      
 95:  
 96:     // 
 97:     // Open the selected adapter 
 98:     // 
 99:  
100:     lpAdapter =   PacketOpenAdapter(AdapterList[Open-1]); 
101:      
102:     if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) 
103:     { 
104:         dwErrorCode=GetLastError(); 
105:         printf("Unable to open the adapter, Error Code : %lx\n",dwErrorCode);  
106:  
107:         return -1; 
108:     }     
109:  
110:     //  
111:     // Allocate a buffer to get the MAC adress 
112:     // 
113:  
114:     OidData = malloc(6 + sizeof(PACKET_OID_DATA)); 
115:     if (OidData == NULL)  
116:     { 
117:         printf("error allocating memory!\n"); 
118:         PacketCloseAdapter(lpAdapter); 
119:         return -1; 
120:     } 
121:  
122:     //  
123:     // Retrieve the adapter MAC querying the NIC driver 
124:     // 
125:  
126:     OidData->Oid = OID_802_3_CURRENT_ADDRESS; 
127:  
128:     OidData->Length = 6; 
129:     ZeroMemory(OidData->Data, 6); 
130:      
131:     Status = PacketRequest(lpAdapter, FALSE, OidData); 
132:     if(Status) 
133:     { 
134:         printf("The MAC address of the adapter is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", 
135:             (PCHAR)(OidData->Data)[0], 
136:             (PCHAR)(OidData->Data)[1], 
137:             (PCHAR)(OidData->Data)[2], 
138:             (PCHAR)(OidData->Data)[3], 
139:             (PCHAR)(OidData->Data)[4], 
140:             (PCHAR)(OidData->Data)[5]); 
141:     } 
142:     else 
143:     { 
144:         printf("error retrieving the MAC address of the adapter!\n"); 
145:     } 
146:  
147:     free(OidData); 
148:     PacketCloseAdapter(lpAdapter); 
149:     return (0); 
150: } 
151: 

运行后获得mac地址

Packet.dll test application. Library version:4.0.0.1040
Adapters installed:

1- \Device\NPF_GenericDialupAdapter

2- \Device\NPF_{B797EC79-A74B-40E4-96E7-0786726CC3C2}

3- \Device\NPF_{B513B814-5657-417F-B515-965AEAC13B83}

Select the number of the adapter to open : 2
The MAC address of the adapter is 02:ff:54:55:4e:01

使用WinPcap获取网卡MAC地址的更多相关文章

  1. Python 获取 网卡 MAC 地址

    /*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...

  2. php获取网卡MAC地址源码

    <?php /** 获取网卡的MAC地址原码:目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetMacAddr{ var $return_array = ...

  3. 转: 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...

  4. windows平台下获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    转自http://blog.csdn.net/jhqin/article/details/5548656,如有侵权,请联系本人删除,谢谢!! 头文件:WMI_DeviceQuery.h /* ---- ...

  5. (转)通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...

  6. 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    转载:https://www.cnblogs.com/tlduck/p/5132738.html #define _WIN32_DCOM #include<iostream> #inclu ...

  7. matlab 获取网卡MAC地址

    输入命令 [sta,MACres] =  dos('getmac'); 其中MACres 存储的信息即为网卡的 相关信息. 如果想判断读取的网卡信息是否有指定信息可以如下输入 USER1 = strf ...

  8. 获取CPU序列号、网卡MAC地址、硬盘序列号

    <pre name="code" class="csharp"> using System; using System.Collections; u ...

  9. 获取客户端网卡MAC地址和IP地址实现JS代码

    获取客户端网卡MAC地址和IP地址实现JS代码 作者: 字体:[增加 减小] 类型:转载   获取客户端的一些信息,如IP和MAC,以结合身份验证,相信很多人都会这样做吧,我们这里用Javascrip ...

随机推荐

  1. 可直接复制粘贴的boostrap图标库网址

    1:http://fontawesome.dashgame.com/ 2:http://www.kuiyu.net/art-34.html 3:http://www.bootcss.com/p/fon ...

  2. javascrit开发的基本代码结构的

    今天看到群里一个demo,简单看了一下. 然后自己就写了一个通用的javascrit开发的基本代码结构的js文件. 代码例如以下: (function($,win){ //定义全局变量对象 var o ...

  3. 排查一般MySQL性能问题

    排查一般MySQL性能问题,通常要记录下面几项信息: 1.mysql> show processlist; 2.mysql> show engine innodb status\G 3.表 ...

  4. 【7.89%】【BNUOJ 52303】Floyd-Warshall

    Time limit: 2 seconds Memory limit: 1024 megabytes In ICPCCamp, there are n cities and m (bidirectio ...

  5. Win10安装后必做的优化,解决磁盘100%占用

    Win10安装后必做的优化,解决磁盘100%占用 01关闭家庭组 控制面板–管理工具–服务– HomeGroup Listener和HomeGroup Provider禁用. 02关闭磁盘碎片整理.自 ...

  6. Android自定义组件系列【7】——进阶实践(4)

    上一篇<Android自定义组件系列[6]--进阶实践(3)>中补充了关于Android中事件分发的过程知识,这一篇我们接着来分析任老师的<可下拉的PinnedHeaderExpan ...

  7. Spring MVC学习:配置简解

    http://blog.csdn.net/heirenheiren/article/details/41485485

  8. JVM 调优 —— OutOfMemory

    零. 简单介绍 OutOfMemory 意思就是须要申请更大的内存, 可是内存限制无法申请到须要的内存. 一. 解决方法 基本上解决方向有两种: 检查程序是否有问题. 是不是写死循环不停地创建并持有对 ...

  9. 最新国内外可用SVN托管仓库有哪些

    最新国内外可用SVN托管仓库哪些 一.总结 一句话总结:用SVNBucket和SourceForge 二.最新国内外可用SVN托管仓库推荐 这几年很多SVN托管平台都基本不维护或者直接关闭了,我翻遍了 ...

  10. Android自定义控件View(一)

    虽然Android API给我们提供了众多控件View来使用,但是鉴于Android的开发性,自然少不了根据需求自定义控件View了.比如说QQ头像是圆形的,但是纵观整个Android控件也找不到一个 ...