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

Release Information

Function introduced in Junos OS Release 9.0.

Support for Python added in Junos OS Release 16.1R1 on QFX Series switches and ACX Series, MX Series, PTX Series, and T Series routers.

Support for Python added in Junos OS Release 17.1R1 on ACX500, ACX1000, ACX1100, ACX2000, ACX2100, ACX2200, and ACX4000 routers, and EX Series switches.

Support for Python added in Junos OS Release 17.3R1 on SRX1500, SRX4100, SRX4200, SRX5400, SRX5600, and SRX5800 devices and vSRX instances.

Support for Python added in Junos OS Release 18.3R1 on ACX5048 and ACX5096 routers.

Description

Parse an IPv4 or IPv6 address.

Parameters

ipaddressIPv4 or IPv6 address.
netmaskNetmask defining the network portion of the address.
prefix-lengthPrefix length defining the number of bits used in the network portion of the address.

Return Value

resultAn 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.