nslookup and IP addresses

Edwin Kremer edwin at praxis.cs.ruu.nl
Tue Nov 28 23:52:24 AEST 1989


In article <2104 at ruuinf.cs.ruu.nl> edwin at cs.ruu.nl (Edwin Kremer) writes:

  > In article <6027 at lindy.Stanford.EDU> odin at ucscb.UCSC.EDU (Jon Granrose)
  > writes:
  >  >	Can anyone tell me a reliable way to find the site name associated
  >  > with a given IP address?  Example:  say I have address 128.114.133.1
  >  > which happens to be a local machine ssyx.ucsc.edu.

 To what <edwin at cs.ruu.nl> responds with:

 > This is how I usually do it (I don't know if there are
 > easier ways):

 ... lots of stuff deleted ...

I didn't like my solution that much after all, so I decided to write
a very small C program to solve this problem. I know this is not the
right group to post sources, but I thought it's to small to bother
the comp.sources.unix moderator, so here it is in a shell archive
at the end of this message. Instructions on how to make are in the 
Makefile. I've tried this program on both HP-UX 6.5 (yes, we're
running a nameserver on our HP9000/370) and SunOS 4.0.3 on
an old ;-) Sun 3/60.

		Good luck,
					--[ Edwin ]--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile iname.c
# Wrapped by edwin at cs.ruu.nl on Tue Nov 28 13:41:10 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1089 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X###############################################################################
X#	I used this one on HP-UX 6.5
X###############################################################################
XCFLAGS	= +O1
XLDFLAGS	= -L /local/usr/lib/bind -lresolv -lBSD -q -s
X
X###############################################################################
X#	I used this one on SunOS 4.0.3
X###############################################################################
XCFLAGS	= -O
XLDFLAGS	= -lresolv -s
X
X###############################################################################
X#	Change this to whatever you prefer
X###############################################################################
XBIN	= /local/bin
XUSER	= edwin
XGROUP	= staff
XMODE	= 0711
X
X###############################################################################
X#	Shouldn't need to change anything below
X###############################################################################
Xiname	: iname.o
X	$(CC) $? -o $@ $(LDFLAGS)
X
Xinstall	: iname
X	cp $? $(BIN)/$?
X	cd $(BIN) ; chown $(USER) $? ; chgrp $(GROUP) $? ; chmod $(MODE) $?
END_OF_FILE
if test 1089 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'iname.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'iname.c'\"
else
echo shar: Extracting \"'iname.c'\" \(1002 characters\)
sed "s/^X//" >'iname.c' <<'END_OF_FILE'
X/*
X *	@(#) iname.c	1.0	89/11/28	EHK
X *
X *	iname		- return fully qualified domain name of
X *			  given internet address.
X */
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <netdb.h>
X
Xstatic char	*RcsId = "$Header: iname.c,v 1.1 89/11/28 13:16:22 edwin Exp $";
X
Xstatic struct in_addr	in;		/* Internet address structure	*/
Xstatic char		*p;		/* Name of this program		*/
X
Xmain(argc, argv)
X	int	argc;
X	char	*argv[];
X{
X	struct hostent	*he;	/* Host info returned if successful	*/
X	char		*inet;	/* ASCII representation of adress	*/
X
X	p = argv[0];
X
X	if ( argc != 2 )
X		printf("Usage: %s  dot_notation_inet_address\n", p), exit(-1);
X
X	inet = argv[1];			/* Get internet address		*/
X	in.s_addr = inet_addr(inet);	/* network byte order		*/
X
X	he = gethostbyaddr((char *) &in, sizeof(struct in_addr), AF_INET);
X	if ( he == (struct hostent *) 0 )
X		fprintf(stderr, "%s: can't resolve %s\n", p, inet), exit(-1);
X	
X	printf("%s = %s\n", inet, he->h_name);
X
X	exit(0);
X}
END_OF_FILE
if test 1002 -ne `wc -c <'iname.c'`; then
    echo shar: \"'iname.c'\" unpacked with wrong size!
fi
# end of 'iname.c'
fi
echo shar: End of shell archive.
exit 0

--
Edwin Kremer, Department of Computer Science, University of Utrecht
Padualaan 14,  P.O. Box 80.089,  3508 TB  Utrecht,  The Netherlands
Phone : +31 - 30 - 534104     |     Telefax: +31 - 30 - 513791
E-Mail: edwin at cs.ruu.nl       |     UUCP to: ...!hp4nl!ruuinf!edwin



More information about the Comp.unix.questions mailing list