1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <pre>
<?php
$liste=array(
'telnet 100.0.0.1 (login/pass)',
'telnet 100.0.0.1/100.11.0.1 (login/pass)',
'ssh -l login 45.25.26.10 (pass)',
'telnet hostname (login/pass)',
'ssh -l login hostname (pass)',
'sudo su - login (pass)',
'telnet 198.21.13.47 (login/ )',
'telnet 198.21.13.47 ()',
);
$ip='\d+\.\d+\.\d+\.\d+';
$pattern='#(telnet|ssh|sudo)(?: -l| su -)? (\w+|'.$ip.')[ /](\w+|'.$ip.')? ?\((\w+)?/?(?:(\w+)?|\s*)\).*#';
echo htmlentities($pattern).'<br>';
foreach($liste as $test) {
preg_match($pattern, trim($test) , $results);
echo '<b>* Test : <u>'.htmlentities($test).'</u></b><br>';
// var_dump($results);
array_shift($results); // on vire le masque entier
$aff=array('commande','IP','IP2','hostname','login','pass');
foreach($aff as $champ) $$champ='';
$commande=array_shift($results);
@list($param1, $param2)=$results;
if (!empty($param1)) {
if (preg_match('#'.$ip.'#', $param1) === 1) {
$IP=$param1;
} else {
$hostname=$param1;
}
}
if (!empty($param2)) {
if (preg_match('#'.$ip.'#', $param2) === 1) {
$IP2=$param2;
} else {
$hostname=$param2;
}
}
if (empty($IP) && !empty($IP2)) {
$IP=$IP2;
$IP2='';
}
switch($commande) {
case 'telnet':
@list(,,$login,$pass)=$results;
break;
case 'ssh':
@list($login,,$pass)=$results;
if (!empty($IP)) $hostname='';
break;
case 'sudo':
@list($login,,$pass,$hostname)=$results;
break;
}
echo '<table border=1>';
echo '<tr><td>'.implode('</td><td>', $aff).'</td></tr>';
echo '<tr>';
foreach($aff as $champ) {
echo '<td>'.$$champ.'</td>';
}
echo '</tr></table>';
echo '<br><br>';
}
?>
</pre> |
Partager