convert between numeric and dotted-decimal IPv4 forms.

Description

ip_to_numeric takes IP addresses stored in their human-readable representation ("192.168.0.1") and converts it to a numeric representation (3232235521). numeric_to_ip performs the same operation, but in reverse. Due to limitations in R's support for colossally big numbers, this currently only works for IPv4 IP addresses.

Usage

1
2
3
ip_to_numeric(ip_addresses)

numeric_to_ip(ip_addresses)

Arguments

ip_addresses

a vector of IP addresses, in their numeric or dotted-decimal form depending on the function.

Value

For ip_to_numeric: a vector containing the numeric representation of ip_addresses. If an IP is invalid (either because it's an Ipv6 address, or isn't an IP address at all) the returned value for that IP will be 0.

For numeric_to_ip: a vector containing the dotted-decimal representation of ip_addresses, as character strings. If a value cannot be resolved to an IPv4 address, it will appear as "0.0.0.0" or an empty string.

Examples

1
2
3
4
5
6
7
#Convert your local, internal IP to its numeric representation.
ip_to_numeric("192.168.0.1")
#[1] 3232235521

#And back
numeric_to_ip(3232235521)
#[1] 192.168.0.1"