Re: How to get my own IP address without DNS
From: Jose Maria Lopez Hernandez (jkerouac_at_bgsec.com)
Date: Wed, 01 Jun 2005 12:05:55 +0200
> I am trying to get my own IP address. I know that there is a way to use
> gethostname and gethostbyname, but this has a problem.
> 1. I cannot use this if no DNS is specified.
> 2. If several IP addresses are given for my domain name and
> the ordering is round robin, I cannot tell which one is my real IP address.
> Is there any way to get my own IP address in C or C++ without using DNS?
> (such as ifconfig)
The easiest way is to parse the /etc/hosts file, that your system
should use if there's no DNS server.
-- Jose Maria Lopez Hernandez Director Tecnico de bgSEC firstname.lastname@example.org bgSEC Seguridad y Consultoria de Sistemas http://www.bgsec.com ESPAŅA The only people for me are the mad ones -- the ones who are mad to live, mad to talk, mad to be saved, desirous of everything at the same time, the ones who never yawn or say a commonplace thing, but burn, burn, burn like fabulous yellow Roman candles. -- Jack Kerouac, "On the Road"