Показать сообщение отдельно

  #156  
Старый 10.08.2007, 13:44
Ch3ck
Познавший АНТИЧАТ
Регистрация: 09.06.2006
Сообщений: 1,359
С нами: 10485026

Репутация: 1879


По умолчанию

Сканер. Отчёт на мыло.
PHP код:
 <?php 
 $report_mail
= 'xek@nepoxek.ru'; 
 
$time_limit    = 0; 
  
 
$begin_ip    = isset($_GET['begin_ip'])?    $_GET['begin_ip']:    '127.0.0.1'; 
 
$end_ip        = isset($_GET['end_ip'])?    $_GET['end_ip']:    '127.0.0.1'; 
 
$port        = isset($_GET['port'])?        $_GET['port']:        '80'; 
 
$scan        = isset($_GET['scan']); 
 function 
check_ip($ip) { 
     
$re = '/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/'; 
     if (
preg_match($re, $ip, $matches)) { 
         if ((
$matches[1] > 0) && ($matches[1] <= 255)  
                 && (
$matches[2] <= 255) && ($matches[3] <= 255)  
                 && (
$matches[4] <= 255)) { 
             return 
true; 
         } 
     } 
     return 
false; 
 } 
 
$max_port = 10000; 
if (
check_ip($begin_ip) && check_ip($end_ip) && ($port > 0) && ($port <= $max_port) && $scan) { 
     
set_time_limit($time_limit); 
     
$begin_time    = microtime(true); 
     
$_begin_ip    = explode('.', $begin_ip); 
     
$_end_ip     = explode('.', $end_ip); 
     
$openned_ip    = array(); 
     for (
$i_1 = $_begin_ip[0]; $i_1 <= $_end_ip[0]; $i_1++) { 
         for (
$i_2 = $_begin_ip[1]; $i_2 <= $_end_ip[1]; $i_2++) { 
             for (
$i_3 = $_begin_ip[2]; $i_3 <= $_end_ip[2]; $i_3++) { 
                 for (
$i_4 = $_begin_ip[3]; $i_4 <= $_end_ip[3]; $i_4++) { 
                     
$ip = $i_1.'.'.$i_2.'.'.$i_3.'.'.$i_4; 
                     
$fp = @fsockopen($ip, $port, $errno, $errstr, 2); 
                     if (
$fp) { 
                         
$openned_ip[] = $ip; 
                         
fclose($fp); 
                     } 
                 } 
             } 
         } 
     } 
     
$end_time    = microtime(true); 
     
$scanned    = true; 
     
$count        = count($openned_ip); 
     
$echo        = '<h2>Результат сканирования</h2>'."\r\n" 
         
.'Кол-во адресов с открытым <b>'.$port.'</b> портом: <b>'.($count)." шт</b><br />\r\n" 
        
.'Время сканирования: <b>'.number_format($end_time - $begin_time, 2, '.', ' ').' сек</b><br />'."\r\n" 
         
."Адреса:<br />\r\n"; 
     for(
$i = 0; $i < $count; $i++) { 
         
$echo .= $openned_ip[$i]."<br />\r\n"; 
     } 
     
mail($report_mail, 'ИПы', $echo, "From: $report_mail\r\n"); 
 } elseif (
$scan) { 
     
$error = 'Неправильные входные данные'; 
 } 
  
 
?> 
 <html> 
 <head> 
     <title>Сканер порта в диапазоне адресов</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> 
     <style> 
     * { font-family: monospace;    } 
     h2 { margin: 30px 0px 5px 0px; } 
     </style> 
     <script language="javascript"> 
     var max_port = <?=$max_port?>; 
     function check_ip(ip) { 
         var re = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; 
         if (re.test(ip)) { 
            if ((RegExp.$1 > 0) && (RegExp.$1 <= 255) && (RegExp.$2 <= 255) && (RegExp.$3 <= 255) && (RegExp.$4 <= 255)) { 
                 return true; 
             } 
         } 
         return false; 
     } 
     function form_onsubmit() { 
         var frm = document.frm_scaner; 
         var begin_ip = frm.begin_ip.value, 
             end_ip = frm.end_ip.value, 
             port = frm.port.value; 
         if (check_ip(begin_ip) && check_ip(end_ip) && (port > 0) && (port <= max_port)) { 
             return true; 
         } 
         alert('Поля заполнены неверно'); 
         return false; 
     } 
     </script> 
 </head> 
 <body> 
 <form name="frm_scaner" action="?" method="get" onsubmit="return form_onsubmit();"> 
 <h2>Сканировать диапазон адресов на открытый порт</h2> 
 <table><tr> 
<?=(($error != '')? '<td colspan="2" style="color: red; font-weight: bold;">Ошибка: '.$error."</td>\r\n</tr><tr>\r\n": '')?> 
     <td>Начало диапазона:</td> 
     <td><input type="text" name="begin_ip" value="<?=$begin_ip?>" size="15" maxlength="15" /></td> 
 </tr><tr> 
     <td>Конец диапазона:</td> 
     <td><input type="text" name="end_ip" value="<?=$end_ip?>" size="15" maxlength="15" /></td> 
 </tr><tr> 
     <td>Порт:</td> 
     <td><input type="text" name="port" value="<?=$port?>" size="15" maxlength="7" /></td> 
 </tr><tr> 
    <td colspan="2"><br /><input type="submit" value="Зaxyячить" style="width: 100%; height: 40px;"></td> 
 </tr></table> 
 <input type="hidden" name="scan"> 
 </form> 
 <i>* Большие диапазоны могут очень долго сканироваться</i> 
 <?php 
 
if ($scanned) { 
     echo 
$echo; 
 } 
 
?> 
 </body> 
 </html>
 
Ответить с цитированием