martes, 23 de octubre de 2007

c _obtener_IP_de_servidor

_______
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main(int argc, char *argv[]) {
struct hostent *he;

if (argc!=2) {
printf("Uso: %s hostname\n",argv[0]);
exit(-1);
}
if ((he=gethostbyname(argv[1]))==NULL) {
printf("error gethostbyname()\n");
exit(-1);
}

printf("Nombre del host: %s\n",he->h_name);
printf("Dirección IP: %s\n",inet_ntoa(*((struct in_addr *)he->h_addr)));
exit(0);
}
_______

-------
_programa en c muy útil para obtener la IP de un servidor
-------

No hay comentarios: