##### Page tree

You are viewing an old version of this page. View the current version.

Version 30

Contents:

Scheduled Maintenance: docs.trifacta.com will be offline for maintenance at 3:00pm UTC on Tuesday March 28 for about 15 minutes.

Computes a four-octet internet protocol (IP) address from a 32-bit integer input.

Source value must be a valid integer within the range specified by the formula below. A valid IPv4 address is in the following format:

aaa.bbb.ccc.ddd

NOTE: IPv6 addresses are not supported.

The formula used to compute the integer equivalent of an IP address is the following:

(aaa * 2563) + (bbb * 2562) + (ccc * 256) + (ddd)

So, the formula to compute this IP address is the following:

Inputaaabbbcccddd
X

aaa = floor(Input / (256 3 ))

remainderA = Input - aaa

bbb = floor(remainderA / (256 2 ))

remainderB = remainderA - bbb

ccc = floor(remainderB / 256)

remainderC = remainderB - ccc

ddd = remainderC

Output value:

Output = aaa + '.' + bbb + '.' + ccc + '.' + ddd

Wrangle vs. SQL: This function is part of Wrangle, a proprietary data transformation language. Wrangle is not SQL. For more information, see Wrangle Language.

## Basic Usage

Numeric literal example:

ipfromint(&apos;16909060&apos;)

Output: Returns the IP address 1.2.3.4

Column reference example:

ipfromint(IpInt)

Output: Returns the values of the IpInt column converted to an IP address value.

## Syntax and Arguments

ipfromint(column_int)

ArgumentRequired?Data TypeDescription
column_intYstring or integerName of column or integer literal that is to be converted to an IP address value

### column_int

Name of the column or integer literal whose values are used to compute the equivalent IP address value.

• Missing input values generate missing results.
• Multiple columns and wildcards are not supported.

Usage Notes:

Required?Data TypeExample Value
YesInteger literal or column reference16909060

## Examples

### Example - Convert IP addresses to integers

This examples illustrates how you can convert IP addresses to numeric values for purposes of comparison and sorting.

Functions:

ItemDescription
IPTOINT Function Computes an integer value for a four-octet internet protocol (IP) address. Source value must be a valid IP address or a column reference to IP addresses.
IPFROMINT Function Computes a four-octet internet protocol (IP) address from a 32-bit integer input.

Source:

192.0.0.1
10.10.10.10
1.2.3.4
1.2.3
http://12.13.14.15
https://16.17.18.19

Transformation:

When the above data is imported, the application initially types the column as URL values, due to the presence of the http:// and https:// protocol identifiers. Select the IP Address data type for the column. The last three values are listed as mismatched values. You can fix the issues with the last two entries by applying the following transform, which matches on both http:// and https:// strings:

Transformation Name Replace text or pattern IpAddr `http%?://` ''

NOTE: The %? Pattern matches zero or one time on any character, which enables the matching on both variants of the protocol identifier.

Now, only the 1.2.3 value is mismatched. Perhaps you know that there is a missing zero at the end of it. To add it back, you can do the following:

Transformation Name Replace text or pattern IpAddr `1.2.3[end]` '1.2.3.0' true

All values in the column should be valid for the IP Address data type. To convert these values to their integer equivalents:

Transformation Name New formula Single row formula IPTOINT(IpAddr) 'ip_as_int'

You can now manipulate the data based on this numeric key. To convert the integer values back to IP addresses for checking purposes, use the following:

Transformation Name New formula Single row formula IPFROMINT(ip_as_int) 'ip_check'

Results:

Xip_as_intip_check
192.0.0.13221225473192.0.0.1
10.10.10.1016843009010.10.10.10
1.2.3.4169090601.2.3.4
1.2.3.0169090561.2.3.0
12.13.14.1520218215912.13.14.15
16.17.18.1926955419516.17.18.19