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