当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 除了vs.net和写字板,记事本外,有没有更好的程序编辑器,谢谢! 包括 1.关键字显示 2.自动缩进 3.智能感应perferred:) 哪里下载? ......
 ·如何将word文档设为只读的    »显示摘要«
    摘要: 如何将word文档设为只读的?要求不能输入任何内容,即文档内不出现光标 ......


菜鸟问题,在线等待,如何通过机器名获得IP

我获得了局域网上的某个机器名如何获得它的ip啊?  
   
 

NO.1   作者: ksyou

struct   hostent   *hp;  
  struct   sockaddr_in   server_addr;  
  hp=gethostbyname(名字);  
  if(hp==0)  
  {  
  return;  
  }  
  memcpy((char*)&server_addr.sin_addr,(char   *)hp->h_addr,hp->hlength);  
 

NO.2   作者: u2m

char   szHostName[128];  
   
  if(   gethostname(szHostName,   128)   ==   0   )  
  {  
  //   Get   host   adresses  
  struct   hostent   *   pHost;  
  int   i;  
     
  pHost   =   gethostbyname(szHostName);  
     
  for(   i   =   0;   pHost!=   NULL   &&   pHost->h_addr_list[i]!=   NULL;   i++   )  
    {  
    CString   str;  
    int   j;  
     
    for(   j   =   0;   j   h_length;   j++   )  
    {  
    CString   addr;  
     
    if(   j   >   0   )  
    str   +=   ".";  
     
    addr.Format("%u",   (unsigned   int)((unsigned  
    char*)pHost->h_addr_list[i])[j]);  
  str   +=   addr;  
    }  
      //   str   now   contains   one   local   IP   address   -   do   whatever   you   want   to   do   with   it   (probably   add   it   to   a   list)  
    }  
  }  
 

NO.3   作者: xglcm

TOO   ....  
   
  TCHAR   szHostName[MAX_PATH];  
  if   (gethostname(szHostName,MAX_PATH   *   sizeof(TCHAR))   !=   SOCKET_ERROR)  
  {  
  hostent   *pHost;  
  pHost   =   gethostbyname(szHostName);  
  if   (pHost)  
  {  
  m_strIP.Format("%d.%d.%d.%d",\  
  pHost->h_addr_list[0][0]   &   0x00ff,\  
  pHost->h_addr_list[0][1]   &   0x00ff,\  
  pHost->h_addr_list[0][2]   &   0x00ff,\  
  pHost->h_addr_list[0][3]   &   0x00ff);  
  }  
 


    摘要: “都”字该不该加,看兄弟们怎么跟贴啦! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE