Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 冲浪技巧 > windows下实现获得对方网卡mac地址的例子
【标  题】:windows下实现获得对方网卡mac地址的例子
【关键字】:windows,mac
【来  源】:http://blog.chinaunix.net/article.php?articleId=32781&blogId=1574

windows下实现获得对方网卡mac地址的例子

Your Ad Here

获得局域网的机器的MAC地址

//devc++编译,将两个库加载进去

#include <windows.h>
#include <iphlpapi.h>
#include <winsock.h>
#include <winsock2.h>
#include <stdio.h>


#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )

int main( int argc, char * argv[] )
{
int numberOfHost = 1;
struct hostent *remoteHostent;

//处理命令行参数
if ( argc == 3 )
numberOfHost = atoi( argv[2] );
if ( ( argc >3 ) || ( argc < 2 ) )
{
printf( "RmtHost v0.2 - Get remote HostName /MacAddress\n" );
printf( "by ShotgunLabs ( [email]Shotgun@xici.net[/email] )\n\n" );
printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n" );
printf( "Example:\n\tRmtHost.exe 192.168.0.3\n" );
printf( "\tRmtHost.exe 192.168.0.3 2\n\n" );
system("pause");
exit( 0 );
}
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}


int nRemoteAddr = inet_addr( argv[1] );
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
for ( int i = 0; i < numberOfHost; i ++ )
        {
        //获取远程机器名
        sa.s_addr = nRemoteAddr;
        printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
        remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
        if ( remoteHostent )
                printf( "HostName : %s\n",remoteHostent->h_name );
        else
        printf( "gethostbyaddr Error:%d\n",GetLastError() );
       
       
        //发送ARP查询包获得远程MAC地址
        unsigned char macAddress[6];
        ULONG macAddLen = 6;
        iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen);
        if ( iRet == NO_ERROR )
                {
                printf( "MacAddress: " );
                for( int i =0; i<6; i++ )
                        {
                        printf( "%.2x", macAddress[i] );
                        if ( i<5 ) printf( "-" );
                        }               
                printf( "\n" );
                }
        else
        printf( "SendARP Error:%d\n", GetLastError());

        nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );

        }


}

Windows快捷键大全:【上一篇】
windows下手把手教你捕获数据包:【下一篇】
【相关文章】
  • Windows快捷键大全
  • 更改远程登录windows系统默认端口3389的访问
  • 让Windows2000的控制台具备命令自动补齐功能
  • Windows系统中单个文件不能超过2G,否则会出现问题。
  • Windows 2000 安全中心
  • Windows 2003下Discuz!2.0论坛架设方法
  • Windows下使用批处理自动修改网络配置(转)
  • Windows 2003 的SNMP配置
  • Windows XP系统设置
  • Windows XP系统优化设置八招
  • 【随机文章】
  • Inside the C++ Object Model学习笔记[Chap3.0]
  • 使用FOXPRO编一个完整的软件
  • 如何把ASP编写成DLL(2)
  • 暂时忘记Windows和Linux吧:不太出名的BSD也许才是你所需要的
  • An introduction to bitwise operators
  • ado .net
  • ORACLE SQL性能优化系列 (十四) 完结篇
  • 现在开始学习openBSD了!
  • 我们为什么不选择Linux?
  • Unix编程/应用问答中文版 ---2.堆栈相关问题
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.