Für mehrere IP-Adressen den Hostnamen ermitteln

Weitere Beispiele

Beispiel ausführen
In das linke Eingabefeld des Formulares kann man per Copy+Paste einen Text welcher IPs enthält einfügen. (z.B. 205.188.208.72,217.224.211.148, 217.224.213.165 o.ä.) Nach dem Absenden erhält man im rechten Textfeld eine Zuordnung der IPs zu Ihrem Hostnamen, sofern ermittelbar. Tipp, zum Ausprobieren des Skriptes einfach diesen Text hier kopieren.
<?php
/**
* Für mehrere IP-Adressen den Hostnamen ermitteln
*/


$max_ip 50;

$theIPS '';
$result '';

if( isset(
$_POST['IP']) && !empty($_POST['IP'])){
    
$tmp = array();
    
$ips $_POST['IP'];
    
$theIPS get_magic_quotes_gpc()? stripslashes($_POST['IP']):$_POST['IP'];
    
$ips preg_replace('#[^0-9.]+#'','$ips);

    
$tmp_arr explode(','$ips);

    
$one_part '([01]?\d\d?|2[0-4]\d|25[0-5])';

    
$reg_exp "#^$one_part\\.$one_part\\.$one_part\\.$one_part\$#";

    
$result '';
    
$c 0;
    foreach (
$tmp_arr as $t){
         if (!
preg_match($reg_exp$t)){
            continue;
        }
        
$c++;
        if (
$c $max_ip){
            break;
        }
        
$host    gethostbyaddr($t);
        
$tmp[$t] = $host;
        
$result .= "$t$host\n";

    }


    
$_POST['IP'] = join("\n"array_keys($tmp));
}


$my_ip   $_SERVER['REMOTE_ADDR'];

$my_host gethostbyaddr($_SERVER['REMOTE_ADDR']);






echo <<< EOT

<form action="
{$_SERVER['PHP_SELF']}" method="post">
<table>
 <tr>
  <th>IP-Adressen</th>
 </tr>
 <tr>
  <td><textarea name="IP" rows="20" cols="20">
{$theIPS}</textarea></td>
  <td><textarea name="result" rows="20" cols="70">
{$result}</textarea></td>
 </tr>
 <tr>
  <td><input type="hidden" name="SEND" value="true"><input type="submit"></td>
 </tr>
</table>
</form>

<strong>My-IP is 
$my_ip
<br>
My-HOST is 
$my_host</strong>
EOT;
?>

Benutzte Funktionen


Hinweise zum DatenschutzImpressum © 2005-2008 S. Eickhoff