1 | <?php |
||
2 | |||
3 | namespace Jodn14\Models; |
||
4 | |||
5 | /** |
||
6 | * Model for validating an ip address |
||
7 | * |
||
8 | */ |
||
9 | class Validator |
||
10 | { |
||
11 | /** |
||
12 | * calls ipstack with ip parameter |
||
13 | * |
||
14 | * @param string ip-address |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
15 | * @return array |
||
16 | */ |
||
17 | 7 | public static function validateIp($ipAddress) : array |
|
18 | { |
||
19 | //valideringslogik |
||
20 | 7 | $hostname = "undefined host"; |
|
21 | |||
22 | 7 | if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
23 | 1 | $result = $ipAddress . " is a valid IPv6 Address."; |
|
24 | 1 | $hostname = gethostbyaddr($ipAddress); |
|
25 | 7 | } else if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
26 | 7 | $result = $ipAddress . " is a valid IPv4 Address."; |
|
27 | 7 | $hostname = gethostbyaddr($ipAddress); |
|
28 | } else { |
||
29 | 7 | $result = $ipAddress . " is not a valid IP Address."; |
|
30 | } |
||
31 | $data = [ |
||
32 | 7 | "result" => $result, |
|
33 | 7 | "hostname" => $hostname |
|
34 | ]; |
||
35 | |||
36 | 7 | return $data; |
|
37 | } |
||
38 | } |
||
39 |