Subject: Re: Obtaining a host name?
To: Jan Danielsson <jan.danielsson@gmail.com>
From: segv <segv@netctl.net>
List: netbsd-users
Date: 08/14/2005 18:53:11
On Sun, 14 Aug 2005 19:16:13 +0200
Jan Danielsson <jan.danielsson@gmail.com> wrote:


>    I just connect my systems to a socket in the wall, and I get my
> address via dhcp. The network doesn't allow protocols such as http and
> ftp without first logging in. Whereever I try to point a browser, I get
> to the login page. Once I have logged in, I can use http & ftp to reach
> the outside world.
> 
>    The script I mentioned is just a script to automate the login
> process, so I won't have to fire up a web browser. On the logon page, it
> displays the users ip address. I want to compare that ip with the one
> that has been assigned to be by the dhcp server. Parsing the HTML and
> acquiring the ip was easy using HTMLParser in Python, so that's not a
> problem. The problem is acquiring the ip address (in a portable way).
> The script I posted eariler works on my XP system and a friends Linux
> system, but it did not work on my NetBSD system.
> 
>    The problem is not getting the host name, but rather resolving it
> into an ip address. That's the call that fails on NetBSD.
> 
>    As suggested in netbsd-users, I tried removing the "hostname" in
> rc.conf, and restarted. Then, when I typed "hostname" it returned an
> empty string: Ergo, the dhcp isn't handing out host names.

I assume you have 'dhclient=yes' in /etc/rc.conf and on boot NetBSD gets a
valid IP address from the dhcp server. When dhclient runs and assigns IP
address, it should also create /etc/resolv.conf file. This file is used to
resolve IP addresses to host names

# cat /etc/resolv.conf
# Created by dhclient at: Sun Aug 14 09:46:06 BST 2005
search netctl.net
nameserver 192.168.0.254
nameserver 10.0.0.2

If your /etc/resolv.conf file does not contain an entry for a DNS server, or if
there is a firewall that blocks DNS queries unless you log in, you may have
problems with DNS queries, i.e. resolving hostnames and IP addresses.

I don't program in python, so don't really know which functions to use, if you
want to get the IP address of your machine, a simple shell script can do that:

For example my network card is rtk0

# ifconfig rtk0 | grep 'inet ' | awk '{print $2}'
192.168.0.3