1 )? 'S' : '') . ' ба'; $this->push_result_stack($str); $str = 'HOST: '.$tgt; $this->push_result_stack($str); $str = 'DATE: '.date('r'); $this->push_result_stack($str); $this->run_scan($tgt, $protocol, $start_port, $end_port); $this->output_results(); echo $this->out; } private function run_scan($tgt, $protocol, $start_port, $end_port) { switch($protocol) { case 'tcp': $host = 'tcp://'; break; case 'udp': $host = 'udp://'; break; default: $host = 'tcp://'; break; } if($start_port != $end_port) { while($start_port <= $end_port) { //using @ to suppress error on can not connect @$fp = fsockopen($host, $start_port, $errno, $errstr, 0.5); $this->record_result($start_port, $fp); $start_port++; } } else { //using @ to suppress error on can not connect @$fp = fsockopen($host, $start_port, $errno, $errstr, 0.5); $this->record_result($start_port, $fp); } } private function record_result($port, $open = false) { $res = ''; switch($open) { case true: $res = 'OPEN'; break; case false: $res = 'CLOSED'; break; } $this->push_result_stack('PORT '.$port.' '.$res); } private function push_result_stack($str) { array_push($this->result_stack, $str); } private function output_results() { foreach($this->result_stack as $key => $data) { $this->out .= $data."\n"; } } } $scan = new port_scan(); ?>