🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sgi.admin
Article #21

Re: system names from IP

#21
From: Dirk Wisse
Date: Wed, 16 Dec 1992 12:35
85 lines
2154 bytes
hofmann@nova.tat.physik.uni-tuebingen.de (Bernhard Hofmann) writes:

>beck@enterprise.den.mmc.com (Fred R. Beck) writes:

>>Howdy!

>>Has anyone out there ever tried to resolve a system name
>>from an IP number?

>Have a look at the man page of gethostbyaddr. A simple C code should
>do the job.

Like this:

------- cut here ----------


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <netdb.h>


void main (int argc, char **argv)
{
		
    struct hostent
        *ent;
    long unsigned
        adr;
    char *p;

    if (argc!=2)
    {
         fprintf(stderr,"\nusage: %s <IP name or address>\n",argv[0]);
         exit(1);
    }

    ent=gethostbyname (argv[1]);
    if (ent==0)
    {
    	adr=inet_addr(argv[1]);            
    	ent=gethostbyaddr ((char *)&adr,4,2);
    }

    if (ent==0)
    {
	fprintf(stderr,"\nno such name or address\n");
  	exit(1);
    }
    printf("Official name	: %s\n",ent->h_name);
    while ((p= *(ent->h_aliases)) != NULL)
    {
	printf ("Alias		: %s\n", p);
	ent->h_aliases++;
    }
    while ((p= *(ent->h_addr_list)) != NULL)
    {
	printf("Address		: %s ( 0x%08lx )\n", inet_ntoa((struct in_addr *)p), *(unsigned long *)p);
        ent->h_addr_list++;
    }
}


------- cut here ----------


You specify an IP hostname or an IP address on the commandline. You get
all the information there is in the entry form the DNS.


>Have fun,
>Bernhard


The same from me,
Dirk
--
--
Dirk Wisse

Internet: Dirk.Wisse@dnpap.et.tudelft.nl
Technical Details
Message-ID: <dirk.724509354@dutepp18>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!dutrun!donau!dirk
References: <1992Dec14.172453.26933@den.mmc.com> <hofmann.724433734@nova>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.admin
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!dutrun!donau!dirk
From: Dirk.Wisse@dnpap.et.tudelft.nl (Dirk Wisse)
Subject: Re: system names from IP
Message-ID: <dirk.724509354@dutepp18>
Sender: news@donau.et.tudelft.nl (UseNet News System)
Nntp-Posting-Host: dutepp18.et.tudelft.nl
Organization: Delft University of Technology, Dept. of Electrical Engineering
References: <1992Dec14.172453.26933@den.mmc.com> <hofmann.724433734@nova>
Date: Wed, 16 Dec 1992 12:35:54 GMT
Lines: 85