Blogs

Scripting How-To: Resolve an IP address and hostname

By Erdem posted 08-09-2015 04:28

  

Overview

Is it possible to write a script that can resolve an interface IP address, then perform a DNS lookup on the IP (basically an interface to hostname lookup)? This applies to SLAX version 1.0 and higher.

Resolution

 

There's no specific RPC for it:

 

1	phil@dent> show host dent | display xml rpc
2	<rpc-reply xmlns:junos="http://xml.juniper.net/junos/13.3I0/junos">
3	    <message>
4	        xml rpc equivalent of this command is not available.
5	    </message>
6	    <cli>
7	        <banner></banner>
8	    </cli>
9	</rpc-reply>

 

And you get the output in <output> tags:

 

01	phil@dent> show host dent | display xml       
02	<rpc-reply xmlns:junos="http://xml.juniper.net/junos/13.3I0/junos">
03	    <output>
04	        dent.rlab.juniper.net is an alias for den.rlab.juniper.net.
05	        den.rlab.juniper.net has address 10.0.0.7
06	    </output>
07	    <cli>
08	        <banner></banner>
09	    </cli>
10	</rpc-reply>

But you should be able to:

 

1	var $rpc = <command> "show host " _ $host;
2	var $res = jcs:execute($conn, $rpc);
3	var $lines = jcs:break-lines($res/output);
4	for-each ($lines) {
5	    <answer> .;
6	}

Or something like that.

Source

 

Answer by Phil Schafer to Junos Automation (Scripting) Forum question, answered 9-10-2013.


#xml
#Slax
#How-To
#ScriptingHow-To