【Ant】 HOST情報 (例:IPアドレス) を動的に取得するには

HOST情報 を動的に取得するには

 * HostInfo の 「ADDR4」を使用する(以下の仕様を参照)
https://ant.apache.org/manual/Tasks/hostinfo.html

構文

<hostinfo prefix="【変数名】" (任意 host="【ホスト名】")/>
 →後は、「${【変数名】.ADDR4}」で使用する

サンプル : build.xml

例1:hostにlocalhostを指定

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="sample_target" name="SampleCodes">
    <hostinfo prefix="host" host="localhost"/>
    <target name="sample_target">
       <echo message="NAME = ${host.NAME}" />
       <echo message="DOMAIN = ${host.DOMAIN}" />
       <echo message="IP = ${host.ADDR4}" />
       <echo message="IP(v6) = ${host.ADDR6}" />
    </target>
</project>

出力結果

sample_target:
     [echo] NAME = localhost
     [echo] DOMAIN = localdomain
     [echo] IP = 127.0.0.1
     [echo] IP(v6) = 0:0:0:0:0:0:0:1
BUILD SUCCESSFUL
Total time: 293 milliseconds

例2:hostにwww.yahoo.co.jpを指定

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="sample_target" name="SampleCodes">
    <hostinfo prefix="host" host="www.yahoo.co.jp"/>
    <target name="sample_target">
       <echo message="NAME = ${host.NAME}" />
       <echo message="DOMAIN = ${host.DOMAIN}" />
       <echo message="IP = ${host.ADDR4}" />
       <echo message="IP(v6) = ${host.ADDR6}" />
    </target>
</project>

出力結果

sample_target:
     [echo] NAME = f7
     [echo] DOMAIN = top.vip.kks.yahoo.co.jp
     [echo] IP = 183.79.75.234
     [echo] IP(v6) = ::
BUILD SUCCESSFUL
Total time: 4 seconds

例3:hostを指定せず

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="sample_target">
    <hostinfo prefix="host" host="localhost"/>
    <target name="sample_target">
       <echo message="NAME = ${host.NAME}" />
       <echo message="DOMAIN = ${host.DOMAIN}" />
       <echo message="IP = ${host.ADDR4}" />
       <echo message="IP(v6) = ${host.ADDR6}" />
    </target>
</project>