A tool to expand hostnames based on a pattern language and DNS resolution

pip install hostexpand==1.0.2


hostexpand(1) -- expand hostnames based on a pattern language and DNS resolution


hostexpand [options] host-expression [...]


Expand the host-expressionn into new-line separated list hostnames. Check each host in DNS and return only hosts that can be resolved. Short hostnames can be expanded to FQDNs according to the DNS search path in the local DNS resolver.


  • --version: Show version

  • --nrformat=NRFORMAT: Set number format, default is %02i

  • --outputformat=OUTPUTFORMAT: Set the output format. Can be one of shortname, fqdn, or ip. Default is shortname.


The following host-expressions are recognized, different pattern styles can be mixed freely:

  • Patterns: Expressions like foo* are searched in DNS, starting from 1 and going up till no more hosts are found. The NRFORMAT sets the length of the number. In this example foo01, foo02 ... would be searched.

  • Number Ranges: Expressions like foo[5..10] are expanded to foo05, foo06, foo07, foo07, foo09, foo10. Expressions like foo[5:10] are expanded to foo05, foo06, foo07, foo07, foo09.

  • Alternatives: Expressions like {foo|bar} are expanded to foo, bar.

  • File Includes: Expressions including a / are interpreted as a file to read, the file should contain hostnames one per line. # comments and empty lines are ignored.


Installation with pip

It is considered good practice to install all packages available via pip & easy_install in a virtual environment so that your development dependencies are isolated from the system-wide dependencies.

  1. create a virtual environment for building

    virtualenv ve

  2. activate the virtual environment

    source ve/bin/activate

  3. install the hostexpand from PyPi

    pip install hostexpand


Licensed under the GNU General Public License (GPL), see for full license text.