zoukankan      html  css  js  c++  java
  • C++ mac

    code:

    #include
    #include
    #include
    #include "iphlpapi.h"
    #pragma comment ( lib, "ws2_32.lib" )
    #pragma comment ( lib, "Iphlpapi.lib" )
    void 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 /MacAddressn" );
    printf( "by ShotgunLabs ( Shotgun@xici.net )nn" );
    printf( "Usage :ntRmtHost.exe [RemoteIP] nn" );
    printf( "Example:ntRmtHost.exe 192.168.0.3n" );
    printf( "tRmtHost.exe 192.168.0.3 255nn" );
    exit( 0 );
    }
    //初始化SOCKET
    WSADATA wsaData;
    int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
    if ( iRet != 0 )
    {
    printf( "WSAStartup Error:%dn", 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 : %sn", inet_ntoa( sa ) );
    remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
    if ( remoteHostent )
    printf( "HostName : %sn",remoteHostent->h_name );
    else
    printf( "gethostbyaddr Error:%dn",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:%dn", GetLastError());
    nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );
    }
    }
    
  • 相关阅读:
    多线程中static对象
    DPDK l2fwd 浅注
    DPDK编译步骤
    什么是API,SDK和API之间的关系
    linux创建定时任务发送钉钉通知
    python-webdriver中添加cookie,解决添加了图片验证码的问题
    win7下CodeIgniter安装
    XAMPP环境搭建及同类推荐
    Fiddler死活抓不了HTTPS包解决办法
    XSS注入常用语句积累
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1832360.html
Copyright © 2011-2022 走看看