1 Introduction
2 Interface
3 History
4 Legal
Version: 1:2

hostname: Getting Hostname, FQDN, and IP Addresses in Racket

Neil Van Dyke

 (require (planet neil/hostname:1:2))

1 Introduction

This package permits Racket programs to determined the host machine’s hostname and internal IP addresses.
This package currently relies on the "/bin/hostname" and "/sbin/ifconfig" programs, available on various Unix-like systems, like GNU/Linux, FreeBSD, OpenBSD, and Mac OS X.

2 Interface


(get-full-hostname)  (or/c #f string?)

Gets the full hostname (aka, fully-qualified domain name, or FQDN) of the host, or #f if unknown.
> (get-full-hostname)


(get-short-hostname)  (or/c #f string?)

Gets the short hostname (i.e., just the hostname of the immediate host, not qualified with any parent domain names), or #f if unknown.
> (get-short-hostname)


(get-ipv4-addrs [#:normal? normal?    
  #:localhost? localhost?])  (listof string?)
  normal? : boolean? = #t
  localhost? : boolean? = #f
Get a list of IPv4 addresses for this machine, such as gotten from "/sbin/ifconfig".
If normal? is true, then non-localhost addresses are included. If localhost? is true, then localhost addresses are included.
The ordering of the list is unspecified. In event of error, generally an empty list will be returned (and a 'warning message will be posted to current-logger).
> (get-ipv4-addrs)
  '("" "")
> (get-ipv4-addrs #:localhost? #t)
  '("" "" "")

3 History

4 Legal

Copyright 2012 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.