Last Update: Thu Jun 07 20:48:25 -0600 2007


Provides hostname, ip address, and other information for a given host.


   require 'sys/host'
   include Sys

   p Host.hostname
   p Host.ip_addr

   # Some platforms{ |h|
      p h



Returns the current version number of this package (as a string)

Class Methods


Returns the hostname of the current host. This may or not return the FQDN, depending on your system.


Returns a list of IP addresses for the current host (yes, it is possible to have more than one).{ |h| … }

Yields a HostInfo struct for each network adapter on 'host', or an array of HostInfo struct's in non-block form. The exact members of this struct vary depending on your platform.

Exception Classes

Host::Error < StandardError

Raised in the event of a failure for any of the class methods provided with this package. Generally speaking, it means there was a failure in the underlying gethostname() or gethostbyname() calls.

Future Plans

Add support for IPV6. This will be difficult unless I have access to a system on an IPV6 network. Any help on this front apblockquoteciated.


The Windows version of this package uses OLE + WMI. The method returns considerably more information than the *nix versions of this package.

Comments and Questions

Please direct all comments and/or questions to one of the Forums on the project home page at

Known Bugs

None that I'm aware of.

Please log any bugs on the project home page at


Thanks go to Mike Hall, Guy Decoux, and Matz for their help with C extensions in general.

Thanks also go to Richard Stevens for his excellent Unix programming books.




Copyright 2002-2007, Daniel J. Berger, djberg96 at gmail dot com

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Ruby itself.


This package is provided "as is" and without any exblockquotess or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.


Daniel J. Berger
djberg96 at nospame at gmail dot com
imperator on IRC (freenode)

See Also

gethostbyname, gethostbyname_r, gethostname, hostname (Unix) WMI, OLE (Windows)