激活当前屏幕保护及获取网上计算机名及其IP地址

 

1.         如何激活当前屏幕保护程序

// 激活当前屏幕保护程序, jingzhou xu

       PostMessage(WM_SYSCOMMAND,SC_SCREENSAVE,0);

2.         如何获取局域网上计算机名及它们的IP地址

l         连接ws2_32.lib mpr.lib

l         #include winsock2.h

CString strTemp;
struct hostent *host;
 
struct in_addr *ptr; // 检索IP地址 
 
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
WNetOpenEnum( dwScope, NULL, NULL, 
             NULL, &hEnum );
 
WSADATA wsaData;
WSAStartup(MAKEWORD(1,1),&wsaData);
 
if ( hEnum )
{
    DWORD Count = 0xFFFFFFFF;
    DWORD BufferSize = 2048;
    LPVOID Buffer = new char[2048];
    WNetEnumResource( hEnum, &Count, 
        Buffer, &BufferSize );
    NetResource = (NETRESOURCE*)Buffer;
 
    char szHostName[200];
    unsigned int i;
 
    for ( i = 0; 
        i < BufferSize/sizeof(NETRESOURCE); 
        i++, NetResource++ )
    {
        if ( NetResource->dwUsage == 
            RESOURCEUSAGE_CONTAINER && 
            NetResource->dwType == 
            RESOURCETYPE_ANY )
        {
            if ( NetResource->lpRemoteName )
            {
                CString strFullName = 
                    NetResource->lpRemoteName;
                if ( 0 == 
                    strFullName.Left(2).Compare("") )   
                    strFullName = 
                        strFullName.Right(
                            strFullName.GetLength()-2);
 
                gethostname( szHostName, 
                    strlen( szHostName ) );
                host = gethostbyname(strFullName);
 
                if(host == NULL) continue; 
                ptr = (struct in_addr *) 
                    host->h_addr_list[0];                    
 
                // =. 分隔开IP:211.40.35.76.             
                int a = ptr->S_un.S_un_b.s_b1;  // 211           
                int b = ptr->S_un.S_un_b.s_b2;  // 40
                int c = ptr->S_un.S_un_b.s_b3;  // 35
                int d = ptr->S_un.S_un_b.s_b4;  // 76
 
                strTemp.Format("%s -->  %d.%d.%d.%d",
                    strFullName,a,b,c,d);
                AfxMessageBox(strTemp);
            }
        }
    }
 
    delete Buffer;
    WNetCloseEnum( hEnum ); 
}
 
WSACleanup();

 

 

 

联系方式:

EMAIL:jingzhou_xu@163.com

未来工作室(Future Studio)

 

  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值