Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!mucs!cns!jf From: jf@ap.co.umist.ac.uk (John Forrest) Newsgroups: comp.sys.apollo Subject: Re: internet address Message-ID: <1991Mar2.173314.9590@cns.umist.ac.uk> Date: 2 Mar 91 17:33:14 GMT References: <9102261044.AA02546@apo.esiee.fr> <5011a909.20b6d@apollo.HP.COM> Sender: news@cns.umist.ac.uk (Usenet news) Organization: comp Lines: 48 In article <5011a909.20b6d@apollo.HP.COM> ced@apollo.HP.COM (Carl Davidson) writes: >From article <9102261044.AA02546@apo.esiee.fr>, by bonnetf@apo.esiee.fr (bonnet-franck): >> Hi, >> >> Does somebody knows how to get the internet address of a machine >> when I am working on it ( whithout looking in /etc/hosts ) ? >> > >I use a shell command: > > % /etc/ping `/etc/hostname` 64 1 > >which says: > > ping the host I'm logged into once, with a 64 byte packet. > >If you need to get just the Internet address, you can extract it from the >with your favorite test reprocessor, i.e. sed, awk, perl,... > I suddenly found myself needing a unique number for each workstation, and the Internet address seemed more portably than trying to discover how to get hold of the Apollo node id. Anyway, based on what I said before, gethostid(2) and/or hostid(1) seem the easiest way. Unfortunately on our OS10.1 systems you actually have to set this up (probably latter versions as well) by adding: hostid `hostname` to /etc/rc.local (preferably at the end once BIND and everything are working ok). Having done this, you can simply invoke: hostid from a shell script, or use: extern long gethostid(void) from a program. Easy isn't it, with no need of network usage nor sed/awk/perl scripts. Of course, hostid does return a hex value, so if you want it in some otherform, you had best write a program that invokes gethostid and prints out the value in the style you want. John Forrest Dept of Computation UMIST