Version: 1:2
hostname: Getting Hostname, FQDN, and IP Addresses in Racket
(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
Gets the full hostname (aka, fully-qualified domain name, or
FQDN) of the host, or #f if unknown.
> (get-full-hostname) "computer.lan"
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) "computer"
procedure
(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) '("192.168.141.99" "192.168.1.112")
> (get-ipv4-addrs #:localhost? #t) '("127.0.0.1" "192.168.141.99" "192.168.1.112")
3 History
- PLaneT 1:2 —
2012-10-05 Added get-ipv4-addrs.
- PLaneT 1:1 —
2012-09-29 Fixed problem with "main.rkt".
- PLaneT 1:0 —
2012-09-29 Initial release.
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.