C   81

hostname

Guest on 25th April 2022 10:17:37 PM

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <winsock2.h>
  4.  
  5. int main() {
  6.  WSADATA WSAData;
  7.     WSAStartup(MAKEWORD(2,0), &WSAData);
  8.  
  9. struct hostent *host;
  10. int i;
  11. host = gethostbyname("www.google.com");
  12. if (host != NULL) {
  13.         printf("Nom officiel : %s\n",host->h_name);
  14.         for (i = 0; host->h_aliases[i] != NULL; i++)
  15.         printf("Alias : %s\n",host->h_aliases[i]);
  16.         for (i = 0; host->h_addr_list[i] != NULL; i++)
  17.         printf("Adresse : %s\n",
  18.         inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
  19. }
  20. WSACleanup();
  21.  
  22. return 0;
  23. }

Raw Paste


Login or Register to edit or fork this paste. It's free.