Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

parse-ip() Function (SLAX and XSLT) and parse_ip() (Python)

Namespaces

Python Syntax

SLAX Syntax

XSLT Syntax

Description

Parse an IPv4 or IPv6 address.

Parameters

ipaddress

IPv4 or IPv6 address.

netmask

Netmask defining the network portion of the address.

prefix-length

Prefix length defining the number of bits used in the network portion of the address.

Return Value

result

An array containing the following information. In SLAX and XSLT scripts, the array index starts at 1. In Python scripts, the array index begins at 0.

  • Host IP address (or NULL in the case of an error)

  • Protocol family (inet for IPv4 or inet6 for IPv6)

  • Prefix length

  • Network address

  • Network mask in dotted decimal notation for IPv4 addresses (left blank for IPv6 addresses)

Usage Examples

The following two SLAX examples parse an IPv4 address and an IPv6 address and detail the resulting output:

  • $addr[1] contains the host address 10.1.2.10.

  • $addr[2] contains the protocol family inet.

  • $addr[3] contains the prefix length 24.

  • $addr[4] contains the network address 10.1.2.0.

  • $addr[5] contains the netmask for IPv4 255.255.255.0.

  • $addr[1] contains the host address 2001:db8:0:c50:8a:800:200c:417a.

  • $addr[2] contains the protocol family inet6.

  • $addr[3] contains the prefix length 32.

  • $addr[4] contains the network address 2001:db8::.

  • $addr[5] is blank for IPv6 ("").

The following Python statement parses an IPv4 address. The values in the addr array are shown. Note that the array index begins at 0.

  • $addr[0] contains the host address 10.1.2.10.

  • $addr[1] contains the protocol family inet.

  • $addr[2] contains the prefix length 24.

  • $addr[3] contains the network address 10.1.2.0.

  • $addr[4] contains the netmask for IPv4 255.255.255.0.

Release Information

Function introduced in Junos OS Release 9.0.

Support for Python added in Junos OS Release 16.1R1.