Skip to content

Commit c027835

Browse files
committed
ip helper
1 parent 902bd3e commit c027835

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

packages/http/src/Helper/IpHelper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ private function __construct()
2020
{
2121
}
2222

23+
public static function isIp(string $ip): bool
24+
{
25+
return static::isIpv4($ip) || static::isIpv6($ip);
26+
}
27+
28+
public static function isIpv4(string $ip): bool
29+
{
30+
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
31+
}
32+
33+
public static function isIpv6(string $ip): bool
34+
{
35+
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
36+
}
37+
2338
/**
2439
* Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.
2540
*

0 commit comments

Comments
 (0)