AAA Главная
Примеры PHP Примеры JavaScript Примеры Ajax Примеры CSS,HTML

Получение информации об IP-адресе, домене


Network Query Tool (NQT) это комплексное решение для получения информации о домене или IP адресе. Вместо ручного запуска различных unix команд или посещения многих сайтов для исследования хоста, просто загрузите Network Query Tool и введите имя хоста или IP адрес. NQT сделает следующее: обратный поиск, запрос DNS (dig), whois (владелец домена), whois (владелец IP), проверку порта, ping и traceroute.


Host Information Host Connectivity

Resolve/Reverse Lookup
Get DNS Records
Whois (Web)
Whois (IP owner)

Check port:
Ping host
Traceroute to host
Всё

if(phpversion() >= "4.2.0"){
   extract($_POST);
   extract($_GET);
   extract($_SERVER);
   extract($_ENV);
}
?>
<html>
<head>
<title>Network Query Tool</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
</head>

<body bgcolor="#FFFFFF">
<div align="center">
  <h2>Network Query Tool</h2>
  <form method="post">
    <table width="60%" border="0" cellspacing="0" cellpadding="1">
      <tr bgcolor="#9999FF">
        <td width="50%" bgcolor="#6666FF"><font size="2" color="#FFFFFF"><b>Host Information</b></font></td>
        <td bgcolor="#6666FF"><font size="2" color="#FFFFFF"><b>Host Connectivity</b></font></td>
      </tr>
      <tr valign="top" bgcolor="#CCCCFF">
        <td>
          <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
            <input type="radio" name="queryType" value="lookup"> Resolve/Reverse Lookup<br>
            <input type="radio" name="queryType" value="dig"> Get DNS Records<br>
            <input type="radio" name="queryType" value="wwwhois"> Whois (Web)<br>
            <input type="radio" name="queryType" value="arin"> Whois (IP owner)</font></p>
        </td>
        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
          <input type="radio" name="queryType" value="checkp"> Check port:
          <input type="text" name="portNum" size="5" maxlength="5" value="80">
          <br>
          <input type="radio" name="queryType" value="p"> Ping host<br>
          <input type="radio" name="queryType" value="tr"> Traceroute to host<br>
          <input type="radio" name="queryType" value="all" checked> Всё</font></td>
      </tr>
      </table>
  <table width="60%" border="0" cellspacing="0" cellpadding="1"><tr bgcolor="#9999FF">
        <td colspan="2">
          <div align="center">
            <input type="text" name="target" value="Укажите домен или IP-адрес" onFocus="if(this.defaultValue==this.value)this.value=''">
            <input type="submit" name="Submit" value="Показать">
          </div>
        </td>
      </tr>
    </table>
  </form>
</div>
<?
#Global kludge for new gethostbyaddr() behavior in PHP 4.1x
$ntarget = "";

function mmessage($msg){
echo "<font face=\"verdana,arial\" size=2>$msg</font>";
}

function lookup($target){
global $ntarget;
$msg = $target." resolved to ";
if( preg_match("/[a-zA-Z]/", $target) )  $ntarget = @gethostbyname($target);
else                              $ntarget = @gethostbyaddr($target);
$msg .= $ntarget;
mmessage($msg);
}

function dig($target){
global $ntarget;
mmessage("<p><b>DNS Query Results:</b><blockquote>");
#$target = gethostbyaddr($target);
#if (! preg_match("/[a-zA-Z]/", ($target = gethostbyaddr($target))) )
if( (!preg_match("/[a-zA-Z]/", $target) && (!preg_match("/[a-zA-Z]/", $ntarget))))
  $msg .= "Can't do a DNS query without a hostname.";
else{
  if(!preg_match("/[a-zA-Z]/", $target)) $target = $ntarget;
  if (! $msg .= trim(nl2br(`dig any '$target'`))) #bugfix
    $msg .= "The <i>dig</i> command is not working on your system.";
  }
#TODO: Clean up output, remove ;;'s and DiG headers
$msg .= "</blockquote></p>";
mmessage($msg);
}

function wwwhois($target){
global $ntarget;
$server = "whois.crsnic.net";
mmessage("<p><b>WWWhois Results:</b><blockquote>");
#Определяю WHOIS server
if((preg_match("\.com\$|\.net\$|\.edu\$", $target)) || (preg_match("\.com\$|\.net\$|\.edu\$", $ntarget)))
  $server = "whois.crsnic.net";
else if((preg_match("\.info\$", $target)) || (preg_match("\.info\$", $ntarget)))
  $server = "whois.afilias.net";
else if((preg_match("\.org\$", $target)) || (preg_match("\.org\$", $ntarget)))
  $server = "whois.corenic.net";
else if((preg_match("\.name\$", $target)) || (preg_match("\.name\$", $ntarget)))
  $server = "whois.nic.name";
else if((preg_match("\.biz\$", $target)) || (preg_match("\.biz\$", $ntarget)))
  $server = "whois.nic.biz";
else if((preg_match("\.us\$", $target)) || (preg_match("\.us\$", $ntarget)))
  $server = "whois.nic.us";
else if((preg_match("\.cc\$", $target)) || (preg_match("\.cc\$", $ntarget)))
  $server = "whois.enicregistrar.com";
else if((preg_match("\.ws\$", $target)) || (preg_match("\.ws\$", $ntarget)))
  $server = "whois.nic.ws";
else if((preg_match("\.ru\$", $target)) || (preg_match("\.ru\$", $ntarget)))
  $server = "whois.ripn.ru";
else{
  $msg .= "I only support .ru .com, .net, .org, .edu, .info, .name, .us, .cc, .ws, and .biz.</blockquote>";
  mmessage($msg);
  return;
}

mmessage("Connecting to $server...<br><br>");
if (! $sock = @fsockopen($server, 43, $num, $error, 10)){
  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(! preg_match("Whois Server:", $buffer)){
   if(preg_match("no match", $buffer))
     mmessage("NOT FOUND: No match for $target<br>");
   else
     mmessage("Ambiguous query, multiple matches for $target:<br>");
 }
 else{
   $buffer = explode("\n", $buffer);
   for ($i=0; $i<sizeof($buffer); $i++){
     if (preg_match("Whois Server:", $buffer[$i]))
       $buffer = $buffer[$i];
   }
   $nextServer = substr($buffer, 17, (strlen($buffer)-17));
   $nextServer = str_replace("1:Whois Server:", "", trim(rtrim($nextServer)));
   $buffer = "";
   mmessage("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\n");
     while (!feof($sock))
       $buffer .= fgets($sock, 10240);
     @fclose($sock);
   }
}
$msg .= nl2br($buffer);
$msg .= "</blockquote></p>";
mmessage($msg);
}

function arin($target){
$server = "whois.arin.net";
mmessage("<p><b>IP Whois Results:</b><blockquote>");
if (!$target = @gethostbyname($target))
  $msg .= "Can't IP Whois without an IP address.";
else{
  mmessage("Connecting to $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 (preg_match("RIPE.NET", $buffer))
     $nextServer = "whois.ripe.net";
   else if (preg_match("whois.apnic.net", $buffer))
     $nextServer = "whois.apnic.net";
   else if (preg_match("nic.ad.jp", $buffer)){
     $nextServer = "whois.nic.ad.jp";
     #/e suppresses Japanese character output from JPNIC
     $extra = "/e";
     }
   else if (preg_match("whois.registro.br", $buffer))
     $nextServer = "whois.registro.br";
   if($nextServer){
     $buffer = "";
     mmessage("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(" ", "&nbsp;", $buffer);
  $msg .= nl2br($buffer);
  }
$msg .= "</blockquote></p>";
mmessage($msg);
}

function checkp($target,$portNum){
mmessage("<p><b>Checking Port $portNum</b>...<blockquote>");
if (! $sock = @fsockopen($target, $portNum, $num, $error, 5))
  $msg .= "Port $portNum does not appear to be open.";
else{
  $msg .= "Port $portNum is open and accepting connections.";
  @fclose($sock);
  }
$msg .= "</blockquote></p>";
mmessage($msg);
}

function p($target){
mmessage("<p><b>Ping Results:</b><blockquote>");
if (! $msg .= trim(nl2br(`ping -c5 '$target'`))) #bugfix
  $msg .= "Ping failed. Host may not be active.";
$msg .= "</blockquote></p>";
mmessage($msg);
}

function tr($target){
mmessage("<p><b>Traceroute Results:</b><blockquote>");
if (! $msg .= trim(nl2br(`/usr/sbin/traceroute '$target'`))) #bugfix
  $msg .= "Traceroute failed. Host may not be active.";
$msg .= "</blockquote></p>";
mmessage($msg);
}


#If the form has been posted, process the query, otherwise there's
#nothing to do yet
if(!$queryType) exit;

#Make sure the target appears valid

if( (!$target) || (!preg_match("/^[\w\d\.\-]+\.[\w\d]{1,4}$/i",$target)) ){ #bugfix
  mmessage("Ошибка: Неверно указан домен или IP.");
  exit;
  }

#Figure out which tasks to perform, and do them

if( ($queryType=="all") || ($queryType=="lookup") )	lookup($target);
if( ($queryType=="all") || ($queryType=="dig") )	dig($target);
if( ($queryType=="all") || ($queryType=="wwwhois") )	wwwhois($target);
if( ($queryType=="all") || ($queryType=="arin") )	arin($target);
if( ($queryType=="all") || ($queryType=="checkp") )	checkp($target,$portNum);
if( ($queryType=="all") || ($queryType=="p") )		p($target);
if( ($queryType=="all") || ($queryType=="tr") )		tr($target);
?>
</div>
Источник: http://shat.net/php/nqt/ (с изменениями KDG)

.

© Copyright 2008-2016 by KDG