当前位置:首页 » 多媒体相关

假设我的主机有多个IP,我怎么知道有多少个,怎么编程找到他们的


假设我的主机有多个ip,我怎么知道有多少个,怎么编程找到他们的

推荐阅读

  • 博客实名制无法实施的十大理由 [详细内容]
  • 比尔盖茨接受采访谈自己为什么不写Blog [详细内容]
  • 数据线连通问题的解决 [详细内容]
  • AMD在华发双核挑战书 英特尔称没必要迎战 [详细内容]
  • 在Weblogic上配置Hibernate为JNDI [详细内容]
  • V 980刷全屏方法 [详细内容]
  • 英特尔更换公司标识 向消费者电子产品转换 [详细内容]
  • 网友回答:
    网友:myselfway

    gethostname();  
      gethostbyname();  
      可以判断!

    网友:alamb

    iphlp   api

    网友:freebirdsme

    gethostbyname()获得hostent   指针,其中有一个ip的列表,检查之即可!!

    网友:airmain

    给你一个例子:  
       
       
      #include   "stdio.h"  
      #include   "stdlib.h"  
      #include   "winsock2.h"  
       
      int   main()  
      {  
      char   localhostname[250]={0};  
      struct   hostent   *hp;  
      struct   sockaddr_in   sin;  
      wsadata   wsadata;  
      int   i=0;  
       
      if(wsastartup(0x0202,&wsadata)!=0){  
      printf("wsastartup()   failed!\n");  
              return   0;  
      }  
       
      if(gethostname(localhostname,sizeof(localhostname))==socket_error)  
      printf("error   %d\n",getlasterror);  
       
      hp=gethostbyname(localhostname);  
       
      printf("host   name   is:   %s\n",localhostname);  
       
      while(hp->h_addr_list[i])  
      {  
      copymemory(&sin.sin_addr,hp->h_addr_list[i],hp->h_length);  
      printf("host   ip   is:   %s\n",inet_ntoa(sin.sin_addr));  
      i++;  
      }  
       
      wsacleanup();  
      return   0;  
      }  
     

    .

    讨论区

    Login