# TO_IP

The TO_IP function converts an input string to an IP value. If the input cannot be converted, the result is a `null` value and a warning header is added to the response with details about the failure.

## Syntax

`TO_IP(field, options, leading_zeros)`

### Parameters

#### field

The input value to convert. This can be a single- or multi-valued column or an expression.

#### options

Optional. Additional options for the conversion.

#### leading_zeros

Specifies how to handle leading zeros in IPv4 addresses. This is a keyword parameter.

## Examples

Convert two string values to IP addresses and filter the results to include only those within the specified CIDR range:

```esql
ROW str1 = "1.1.1.1", str2 = "foo"
| EVAL ip1 = TO_IP(str1), ip2 = TO_IP(str2)
| WHERE CIDR_MATCH(ip1, "1.0.0.0/8")
```
This example converts two strings to IP values and filters the results by a CIDR range. If a string cannot be converted, the result is `null` and a warning is generated.

Parse an IPv4 address with leading zeros as octal notation, interpreting each octet accordingly:

```esql
ROW s = "1.1.010.1" | EVAL ip = TO_IP(s, {"leading_zeros":"octal"})
```
This example parses an IPv4 address with leading zeros as octal, similar to how `ping` or `ftp` handle such addresses.

Parse an IPv4 address with leading zeros as decimal notation, treating each octet as a standard decimal value:

```esql
ROW s = "1.1.010.1" | EVAL ip = TO_IP(s, {"leading_zeros":"decimal"})
```
This example parses an IPv4 address with leading zeros as decimal, following Java's `InetAddress.getByName` behavior.
