class IPUtils (View source)

deprecated 5.3.0 Use Symfony\Component\HttpFoundation\IpUtils instead

Http utility functions.

Methods

public static 
bool
checkIP(string $requestIP, string|array $ips)

Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.

public static 
bool
checkIP4(string $requestIP, string $ip)

Compares two IPv4 addresses.

public static 
bool
checkIP6(string $requestIP, string $ip)

Compares two IPv6 addresses.

public static 
string
anonymize(string $ip)

Anonymizes an IP/IPv6.

Details

static bool checkIP(string $requestIP, string|array $ips)

Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.

Parameters

string $requestIP

IP to check

string|array $ips

List of IPs or subnets (can be a string if only a single one)

Return Value

bool

Whether the IP is valid

static bool checkIP4(string $requestIP, string $ip)

Compares two IPv4 addresses.

In case a subnet is given, it checks if it contains the request IP.

Parameters

string $requestIP

IPv4 address to check

string $ip

IPv4 address or subnet in CIDR notation

Return Value

bool

Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet

static bool checkIP6(string $requestIP, string $ip)

Compares two IPv6 addresses.

In case a subnet is given, it checks if it contains the request IP.

Parameters

string $requestIP

IPv6 address to check

string $ip

IPv6 address or subnet in CIDR notation

Return Value

bool

Whether the IP is valid

Exceptions

RuntimeException

See also

https://github.com/dsp/v6tools

static string anonymize(string $ip)

Anonymizes an IP/IPv6.

Removes the last byte for v4 and the last 8 bytes for v6 IPs

Parameters

string $ip

Return Value

string