橘子皮

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 char ch[] = "www.163.com";
  HOSTENT *host = NULL;
  
  int iStar = ::GetCurrentTime();  // 开始时间
  host = ::gethostbyname(ch);
  
   if (NULL == host)
    break;
   
   CString ss = host->h_name;
   
   sockaddr_in sa;
   for (int nAdapter=0; host->h_addr_list[nAdapter]; nAdapter++)
   {
    memcpy ( &sa.sin_addr.s_addr, host->h_addr_list[nAdapter],host->h_length);
    // 输出机器的IP地址.
    TRACE("Address: %s/n", inet_ntoa(sa.sin_addr)); // 显示地址串
    
    // 连接所有解析过来的IP
    if (SOCKET_ERROR == connect (s, (sockaddr*)&sa, sizeof(sa)) )
    {
     // AfxMessageBox("连接错误", MB_TOPMOST);
     LogWrite ("解析 %s: 地址(%s) 连接失败",ch,/
      inet_ntoa(sa.sin_addr));
     Sleep(100);
     continue;
    } 
}
TRACE ("耗时 %d毫秒/r/n", GetCurrentTime() - iStar);

posted on 2007-03-07 09:31  橘子皮  阅读(322)  评论(0编辑  收藏  举报