Whois скрипт. Умеет делать whois запросы и пинговать адрес. Сохраняет и выводит внизу страницы последние 10 запросов.(Для этого создать в папке со скриптом текстовый файлlast.txt и поставить права на запись 777 )
whois.php
PHP код:
<?
if (!file_exists("last.txt")) { fclose(fopen("last.txt", "w+")); }
function message($msg){
echo "<font face=\"verdana,arial\" size=2>$msg</font>";
flush();
}
function arin($target){
$server = "whois.arin.net";
message("<p><b>Whois результат:</b><blockquote>");
if (!$target = gethostbyname($target))
$msg .= "Can't IP Whois without an IP address.";
else{
message("Подключаемся к $server...<br><br>");
if (! $sock = fsockopen($server, 43, $num, $error, 20)){
unset($sock);
$msg .= "Timed-out connecting to $server (port 43)";
}
else{
fputs($sock, "$target\n");
while (!feof($sock))
$buffer .= fgets($sock, 10240);
fclose($sock);
}
if (eregi("RIPE.NET", $buffer))
$nextServer = "whois.ripe.net";
else if (eregi("whois.apnic.net", $buffer))
$nextServer = "whois.apnic.net";
else if (eregi("nic.ad.jp", $buffer)){
$nextServer = "whois.nic.ad.jp";
$extra = "/e";
}
else if (eregi("whois.registro.br", $buffer))
$nextServer = "whois.registro.br";
if($nextServer){
$buffer = "";
message("Deferred to specific whois server: $nextServer...<br><br>");
if(! $sock = fsockopen($nextServer, 43, $num, $error, 10)){
unset($sock);
$msg .= "Timed-out connecting to $nextServer (port 43)";
}
else{
fputs($sock, "$target$extra\n");
while (!feof($sock))
$buffer .= fgets($sock, 10240);
fclose($sock);
}
}
$buffer = str_replace(" ", " ", $buffer);
$msg .= nl2br($buffer);
}
$msg .= "</blockquote></p>";
message($msg);
}
function ping($target){
$p=shell_exec ("ping '".addslashes($target)."'");
$p=convert_cyr_string ($p, "a", "w");
message ("<pre>".$p."</pre>");
}
?>
<html>
<head>
<title>Whois service</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body bgcolor="#181818" text=white>
<center>
<?
error_reporting (0);
set_time_limit (0);
$dn=$_GET["dn"];
$dn=str_replace(" ", "", $dn);
if (!isset ($dn) || empty ($dn))
{
?>
<h1>Whois сервис</h1>
<h3>Введите адрес:</h3>
<form action="#" method=get>
<input type=text name=dn><input type=submit value="Do it!"><br>
<table border=0 align=center width=20%>
<tr>
<td width=20><center><input type=radio name=action value=whois checked></center></td>
<td width=80>Только Whois</td>
</tr><tr>
<td width=20><center><input type=radio name=action value=ping></center></td>
<td width=80>Ping</td>
</tr>
</table>
</form>
<br><br>
Последние 10 запросов:<br>
<?
echo implode ("<br>", file ("last.txt"))."<br><br>";
} else {
$action=$_GET["action"];
if ($action == "whois") {
?>
<h1><?=$dn; ?></h1>
</center>
<br>
<?=arin($dn); ?>
<hr>
<center>
<? } else { ?>
<h1><?=$dn; ?></h1>
</center>
<?=ping($dn); ?>
<hr>
<center>
<?
}
$list=file($file='last.txt');
if(($newmess=htmlspecialchars ($action).": ".htmlspecialchars ($dn)."\r\n")!=$list[0])
{ array_unshift ($list, $newmess);
if(isset($list[10])) unset ($list[10]);
$fp=fopen($file,'w');
fwrite($fp, implode('',$list));
fclose($fp); }
}
?>
<br>© Eugen, 2007
</center>
</body>
</html>
|