Chapter 16. Hostname

This task shows the hostname or IP address of the local machine.

To use this task in your build files, include a task definition like this:

    <taskdef name="hostname" classname="ise.antelope.tasks.HostnameTask"/>

Table 16.1. Hostname Task Attributes

propertyName of the property to store the hostname or IPhostnameNo
showipIf true, get the IP address of the local machine.falseNo
nicThe specific name of an interface to get the hostname or IP address of.NoneNo
showallGet all names or IP addresses for all network interfaces on the local machine.falseNo
failonerrorShould the build fail if this task fails?falseNo


      Unit tests for hostname task, not really good as hostname is machine
      dependent, so writing a portable test is hard.

   <target name="test1">
      <a:unset name="hostname"/>
      <echo>hostname: ${hostname}</echo>
      <a:assert name="hostname" exists="true" message="test 1 failed."/>

   <target name="test2">
      <a:unset name="localhost"/>
      <a:hostname property="localhost"/>
      <echo>localhost: ${localhost}</echo>
      <a:assert name="localhost" exists="true" message="test 2 failed."/>

   <target name="test3">
      <a:unset name="localhost"/>
      <a:hostname property="localhost" showall="yes"/>
      <echo>all interfaces: ${localhost}</echo>
      <a:assert name="localhost" exists="true" message="test 3 failed."/>

   <target name="test4">
      <a:unset name="localhost"/>
      <a:hostname property="localhost" showall="yes" showip="yes"/>
      <echo>all interfaces by IP: ${localhost}</echo>
      <a:assert name="localhost" exists="true" message="test 4 failed."/>

   <target name="test5">
      <a:unset name="localhost"/>
      <a:hostname property="localhost" nic="lo" showip="yes"/>
      <echo>nic lo: ${localhost}</echo>
      <a:assert name="localhost" value="lo:" message="test 5 failed."/>


     [echo] hostname: blackdog

     [echo] localhost: blackdog

     [echo] all interfaces: lo:, eth0:,,

     [echo] all interfaces by IP: lo:, eth0:, eth1:, eth2:

     [echo] nic lo: lo: