Conditions | 4 |
Paths | 6 |
Total Lines | 48 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function getIp($ip) : array |
||
29 | { |
||
30 | if (filter_var($ip, FILTER_VALIDATE_IP)) { |
||
31 | $valid = "true"; |
||
32 | } else { |
||
33 | $valid = "false"; |
||
34 | } |
||
35 | |||
36 | if ($valid == "true") { |
||
37 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
||
38 | $ipv = "Ipv4"; |
||
39 | } else { |
||
40 | $ipv = "Ipv6"; |
||
41 | } |
||
42 | |||
43 | $key = implode($this->config); |
||
|
|||
44 | $details = json_decode(file_get_contents("http://api.ipstack.com/{$ip}?access_key={$key}")); |
||
45 | |||
46 | $domain = gethostbyaddr($ip); |
||
47 | $lat = $details->latitude; |
||
48 | $long = $details->longitude; |
||
49 | $country = $details->country_name; |
||
50 | $region = $details->region_name; |
||
51 | $city = $details->city; |
||
52 | |||
53 | return [ |
||
54 | "valid" => $valid, |
||
55 | "ip" => $ip, |
||
56 | "ipv" => $ipv, |
||
57 | "domain" => $domain, |
||
58 | "lat" => $lat, |
||
59 | "long" => $long, |
||
60 | "country" => $country, |
||
61 | "region" => $region, |
||
62 | "city" => $city |
||
63 | ]; |
||
64 | |||
65 | } else { |
||
66 | return [ |
||
67 | "valid" => "Not Valid IP", |
||
68 | "ip" => null, |
||
69 | "ipv" => null, |
||
70 | "domain" => null, |
||
71 | "lat" => null, |
||
72 | "long" => null, |
||
73 | "country" => null, |
||
74 | "region" => null, |
||
75 | "city" => null |
||
76 | ]; |
||
80 |