From Winsite (Feb 1999).

---- LOOKUP program
---- Contributed to the public domain by Yuval Oren 1/11/97

This is a program I quickly wrote so I'd have a "nslookup"-like
command-line utility. It looks up IP addresses for a given name
and vice-versa. You need Windows 95 or Windows NT to run it. I've
also included the source code.

Syntax:

LOOKUP with no parameters gives you the syntax.
LOOKUP <IP address> gives you the host name.
LOOKUP <host name> gives you all IP addresses for that name.
	(try looking up www.microsoft.com!)

If you find this useful and are eternally grateful to me, drop me an
e-mail. Any other comments are welcome, too. Otherwise, just enjoy.

-- Yuval
yuval@ccnet.com
http://www.ccnet.com/~yuval/



---------------------------------------------------
#include <winsock.h>
#include <stdio.h>
#include <string.h>

void error(char *s);
void usage();


void main(int argc, char *argv[])
{
	WSADATA wsaData;
	int err;
	struct hostent *pHostInfo;
	long lIPAddress;
	int i;

	/* Bad or no parameters; show help. */
	if (argc <= 1 || argv[1] == NULL) {
		usage();
		exit(1);
	}

	/* Initialize Windows Sockets */
	err = WSAStartup(MAKEWORD(1,1),&wsaData);
	if (err) {
		error("Could not initialize Windows Sockets.");
		exit(1);
	}

	/* Make sure they have at least WinSock 1.1 */
	if (LOBYTE(wsaData.wVersion) != 1 ||
		HIBYTE(wsaData.wVersion) != 1) {
		error("This program requires Windows Sockets 1.1.");
		WSACleanup();
		exit(1);
	}

	/* Lookup a host name from an IP address */
	if (*argv[1] >= '0' && *argv[1] <= '9') {

		lIPAddress = inet_addr(argv[1]);

		/* Bad IP address; show help */
		if (lIPAddress == INADDR_NONE) {
			error("Bad IP address.");
			usage();
			WSACleanup();
			exit(1);
		}

		pHostInfo = gethostbyaddr((char *) &lIPAddress,4,PF_INET);

		if (pHostInfo == NULL) {
			printf("I have no idea who %s is.\n",argv[1]);
			WSACleanup();
			return;
		}

		printf("%s\'s official name is %s.\n",argv[1],pHostInfo->h_name);

		if (pHostInfo->h_aliases && *pHostInfo->h_aliases) {
			printf("It has the following aliases:\n");
			for (i = 0; pHostInfo->h_aliases[i]; i++)
				printf("\t%s\n",pHostInfo->h_aliases[i]);
		}

	}

	/* Lookup an IP address from a host name */
	else {

		pHostInfo = gethostbyname(argv[1]);

		if (pHostInfo == NULL) {
			printf("I have no idea who %s is.\n",argv[1]);
			WSACleanup();
			return;
		}

		if (pHostInfo->h_name && strcmp(argv[1],pHostInfo->h_name)) {
			printf("%s is really an alias for %s.\n",argv[1],pHostInfo->h_name);

		}

		if (pHostInfo->h_aliases && *pHostInfo->h_aliases
			&& pHostInfo->h_aliases[1]) {
			printf("It has the following aliases:\n");
			for (i = 0; pHostInfo->h_aliases[i]; i++)
				printf("\t%s\n",pHostInfo->h_aliases[i]);
		}

		if (pHostInfo->h_addr_list == NULL || *pHostInfo->h_addr_list == NULL)
			printf("Strange...%s has no IP addresses.\n",argv[1]);
		else if (pHostInfo->h_addr_list[1] == NULL) /* Only 1 address */
			printf("%s\'s IP address is %s.\n",pHostInfo->h_name,
					inet_ntoa(*(struct in_addr *)pHostInfo->h_addr_list[0]));
		else {
			printf("%s has the following addresses:\n",pHostInfo->h_name);
			for (i = 0; pHostInfo->h_addr_list[i]; i++)
				printf("\t%s\n",
					inet_ntoa(*(struct in_addr *)pHostInfo->h_addr_list[i]));
		}


	}
	WSACleanup();
	return;
}

void usage()
{
	fprintf(stderr,"LOOKUP  ");
	fprintf(stderr,"Written by Yuval Oren\n");
	fprintf(stderr,"Usage: LOOKUP <IP address> -- Get name from IP address\n");
	fprintf(stderr,"       LOOKUP <host name > -- Get IP address from name\n");
}

void error(char *s)
{
	fprintf(stderr,"%s\n",s);
}


---------------------------------------------------