/* * This program takes an IP address as the single command line argument * and performs a reverse DNS lookup to determine the host name, if any. * * Eric Myers * Deparment of Physics, University of Michigan, Ann Arbor * @(#) $Id: hname.c,v 1.2 1999/08/02 21:25:05 myers Exp myers $ */ #include #include /* NULL */ #include #include #include #include /* in_addr */ #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ /***#define INTERNIC "internic.net" /* */ #define INTERNIC "whois.ripe.net" main(argc, argv) int argc; char *argv[]; { struct in_addr HostAddr; unsigned long haddr; struct hostent *host; char *HostName; /* Convert string argument to internet address */ HostAddr.s_addr = inet_addr(argv[1]); /* Look up host name using IP address */ host = gethostbyaddr((char *)&HostAddr, sizeof(HostAddr), AF_INET); /* Print name if succesfull, otherwise just the address */ if (host == NULL ) { HostName = inet_ntoa(HostAddr); printf("%s is unknown.\n", HostName); printf("(Try `whois -h %s %s` or variations to find the owner.)\n", INTERNIC, HostName); } else { HostName = host->h_name; printf("%s\n", HostName); } }