Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
4 | class Ping |
||
5 | { |
||
6 | public function ping($host) |
||
7 | { |
||
8 | $is_valid_ip = $this->isValidIp($host); |
||
9 | |||
10 | if ($is_valid_ip) { |
||
11 | |||
12 | exec("ping -n 2 $host", $output, $result); |
||
13 | |||
14 | if ($result === 0) { |
||
15 | |||
16 | return true; |
||
17 | |||
18 | } else { |
||
19 | |||
20 | return false; |
||
21 | |||
22 | } |
||
23 | |||
24 | } else { |
||
25 | |||
26 | $result_url = $this->isValidUrl($host); |
||
27 | |||
28 | if ($result_url != $host) { |
||
29 | |||
30 | return true; |
||
31 | |||
32 | } else { |
||
33 | |||
34 | return false; |
||
35 | |||
36 | } |
||
37 | |||
38 | } |
||
39 | |||
40 | } |
||
41 | |||
42 | public function isValidIp($host) |
||
43 | { |
||
44 | return gethostbyaddr($host); |
||
45 | } |
||
46 | |||
47 | public function isValidUrl($host) |
||
50 | } |
||
51 | |||
52 | } |
||
53 |