psyphi  | Voila un petit code que j'avais pour obtenir l'ip à partir d'un nom d'hôte:
 le code est en C et fonctionne sous Unix et Win32:
  Code :
 - /*
 - * Program name : get_ip.c
 - * author : psyphi
 - * e-mail : psyphi@gmail.com
 - * last update : August 11 2005
 - * compile : gcc -o getip get_ip.c -> Linux
 - *           gcc -o getip get_ip.c -lwsock32 -> Windows
 - * usage : ./getip <hostname>
 - */
 - #include <stdio.h>
 - #include <errno.h>
 - #if defined(WIN32)
 - #include <winsock2.h>
 - #pragma comment(lib, "ws2_32.lib" )
 - #else
 - #include <sys/socket.h>     /* pour avoir AF_INET */
 - #include <netdb.h>          /* pour gethostbyname() & struct hostent */
 - #include <netinet/in.h>     /* pour inet_ntoa() */
 - #endif
 - int main(int argc, char * argv[])
 - {
 -   #if defined(WIN32)
 -   WSADATA WSAData;
 -   WSAStartup(MAKEWORD(2,0), &WSAData);
 -   #endif
 -   if(argc!=2)
 -   {
 -     fprintf(stderr,"Usage : %s <hostname> \n",argv[0]);
 -     exit(1);
 -   }
 -  
 -   struct hostent * host=gethostbyname(argv[1]);
 -  
 -   if(!host)
 -   {
 -     fprintf(stderr,"host error\n" );
 -     exit(1);
 -   }
 -  
 -   fprintf(stdout,"Hostname : %s \n",host->h_name);
 -   fprintf(stdout,"IP adress : %s \n",inet_ntoa(*((struct in_addr * )host->h_addr)));
 -  
 -   return 0;
 - }
 
  |  
    |