Skip to content


Subversion checkout URL

You can clone with
Download ZIP


hilbix edited this page · 6 revisions
Clone this wiki locally


ipof is thought for shell usage to quickly resolve a name to the IP. There is a similar tool gethostip which is part of syslinux, which unfortunately is not able to resolve IPv6.

ipof perhaps is a bit Linux centric, and needs a recent libc.


git clone https://hilbix/misc.git ipof
cd ipof/src
sudo cp ipof /usr/local/bin/

Short use cases:

  • ipof Just outputs the IP of The order is as the IPs are handed out from the library. So you might get different results with different calls.
  • ipof -a Outputs all IPs of, this shows you all IPs
  • ipof -6 Outputs IPv6 of (aka. AAAA record)
  • ipof -4 Outputs IPv4 of (is probably the same as ipof
  • ipof -a -d Outputs resolving dupes, too. I see both IPs 3 times. To understand why you can use following
  • ipof -a -d -x Outputs extended information. Here you can see that the libc resolver tells us different possible protocols to use. This is why disabling dupes checking hands out one IP multiple times.
  • ipof -- Usually names do not start with a dash (-). If you fear that this might happen, as possible with shell variables (like ipof -- "$var") you can use the usual double-hyphen (--).
  • ipof localhost: It uses the libc resolver which parses /etc/hosts, too.
  • ipof -+: Read from stdin, disallowing the use of options
  • ipof -: Read from stdin, you can switch options by entering the -X options.
  • ipof: Prints all the possible options.

Return value

The return value if ipof is 0 (true) only when all names were successfully resolved. Else it returns 1 (false). This way you can use it naturally in shells.

Reading from STDIN

As you probably will notice, ipof -adx fails. As it was written for brevity it has no option parser, instead it just interprets the arguments as they come, and if they start with a dash (-) they are swallowed if they are a valid option. If not they are resolved. This comes handy in interactive mode, as you can use these options anywhere from stdin:

ipof -


Options: --> active
        -h      help
        -?      help
        -       read stdin
        --      end of options
        --file  read file, options on
        -+[fil] read file, no options
        -b      buffered
-->     -u      unbuffered
        -p      progress
-->     -n      no progress
-->     -r      reset error flag
        -e      set error flag
        -o      set ok
        -q      quiet errors
-->     -e      errors
        -x      extended info
-->     -i      ip info
        -v      verbose
-->     -s      silent
        -t      totally silent
-->     -c      clean dupes
        -d      dupes
        -a      show all addresses
-->     -1      show single address
-->     -0      any address format
        -4      IPv4 address format
        -6      IPv6 address format

This way you can start it with ipof - and use it interactively (it does not use readline, though) to resolve hostnames. If you forgot your state, just type -? or -h and you can see your current settings (the --> markers).

Some things in which shall make it more easy to use it in shell scripts:

  • -q: Errors are no more printed. Normally failures are printed to stderr. Note that the return value still tells any failure.
  • -p: Progress indicator. This prints a dot (.) when resolving starts and then another character which shows the outcome (4 for IPv4, x for failure, and so on). If you use it to resolve files you can keep an eye on the progress this way. Perhaps combine with -q.
  • -v: Prints the resolved hostname in front of the IPs. If -a is present, all IPs are printed on the same line.
  • -t: No IPs are printed at all. Similar to ipof >/dev/null but can be switched on and off.
  • -b: Buffered output, in case you want to spare context switches. By default the output is "unbuffered", this means, the output can be seen as soon as it occurs. Note that this covers the progress, too, so you can buffer the progress until you switch back to "unbuffered" mode with -u.
  • -x and -d are probably only interesting for debugging purpose.
  • -+/path/to/file reads a file without allowing options within, just to be sure.

Notes about files:

They are read whitespace separated. So any combination of blanks, as domain names usually do not have blanks in it.


  • It currently only knows IPv4 and IPv6. Other socket families are not yet supported. If you can help with that, you are welcome. (Well, on the paper I am HAM DG8MGV, so it's weird that I cannot support AX25, but currently I do not own any HAM Radio equipment. Sorry.)

  • It was not tested thoroughly. So there might be other bugs. If you find some, please fix and send a pull request. Eventually I will honor. Perhaps create an ipof topic branch for this.

  • It is missing reverse lookup.


"Copyright Less License". This means, not Copyrighted and never Copyrighted. In other words: Free as in Free Beer, Free Speech, Free People and Free Votes.

Something went wrong with that request. Please try again.