home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Programare / cnstats / reports / ipinfo.php < prev    next >
Encoding:
PHP Script  |  2004-06-22  |  3.6 KB  |  100 lines

  1. <?php
  2. $filter=$HTTP_GET_VARS["filter"];
  3.  
  4. $DATELINK="&filter=".urlencode($filter);
  5.  
  6. function islocal($ip) {
  7.     if ($ip=="255.255.255.255") return(true);
  8.     if (substr($ip,0,7)=="192.168") return(true);
  9.     if (substr($ip,0,2)=="10") return(true);
  10.     return(false);
  11.     }
  12.  
  13. function mygethostbyaddr($ip) {
  14.     GLOBAL $LANG;
  15.     if (substr($ip,0,7)=="192.168") return($LANG["local ip"]."<br>192.168.0.0 - 192.168.255.255");
  16.     if (substr($ip,0,2)=="10") return($LANG["local ip"]."<br>10.0.0.0 - 10.255.255.255");
  17.  
  18.     return(gethostbyaddr($ip));
  19.     }
  20.  
  21. $rid=$HTTP_GET_VARS["rid"];
  22. if (!empty($rid)) {
  23.  
  24.     $r=mysql_query("select ip,proxy from cns_log WHERE id='".$rid."'");
  25.     if ($a=mysql_fetch_array($r)) {
  26.         $ip=long2ip($a[0]);
  27.         $proxy=$a[1]==-1?"":long2ip($a[1]);
  28.         if (empty($proxy)) {$proxy=$LANG["not used"];} else $proxy=$proxy." (".mygethostbyaddr($proxy).")";
  29.  
  30.         print $TABLE;
  31.         print "<tr class=\"tbl2\"><td>".$LANG["ip"]."</td><td>".$ip."</td></tr>\n";
  32.         print "<tr class=\"tbl2\"><td>".$LANG["title"]."</td><td>".mygethostbyaddr($ip)."</td></tr>\n";
  33.         print "<tr class=\"tbl2\"><td>".$LANG["proxy"]."</td><td>".$proxy."</td></tr>\n";
  34.  
  35.         $proxy=long2ip($a[1]);
  36.         $country=0;
  37.         // Get country for ip
  38.         if (!islocal($ip)) {
  39.             $r=cnstats_sql_query("SELECT c FROM cns_countries WHERE INET_ATON('".$ip."')>=ip1 AND INET_ATON('".$ip."')<=ip2 LIMIT 1;");
  40.             if (mysql_num_rows($r)==1) $country=mysql_result($r,0,0);
  41.  
  42.             $tld="";
  43.             if ($country=="0") $country=$LANG["other countries"];
  44.             else {
  45.                 $tld=chr($country>>8).chr($country&0xFF);
  46.                 if (isset($COUNTRY[$tld])) $country=$COUNTRY[$tld];
  47.                 else $country=$tld;
  48.     
  49.                 $country="<img src=img/countries/".strtolower($tld).".gif width=18 height=12 border=0 align=absmiddle hspace=4>".$country;
  50.                 }
  51.             print "<tr class=\"tbl2\"><td>".$LANG["country"]."</td><td>".$country."</td></tr>\n";
  52.             }
  53.  
  54.         // Get country for proxy
  55.         if (!islocal($proxy)) {
  56.             $r=cnstats_sql_query("SELECT c FROM cns_countries WHERE INET_ATON('".$proxy."')>=ip1 AND INET_ATON('".$proxy."')<=ip2 LIMIT 1;");
  57.             if (mysql_num_rows($r)==1) $country=mysql_result($r,0,0);
  58.  
  59.             $tld="";
  60.             if ($country=="0") $country=$LANG["other countries"];
  61.             else {
  62.                 $tld=chr($country>>8).chr($country&0xFF);
  63.                 if (isset($COUNTRY[$tld])) $country=$COUNTRY[$tld];
  64.                 else $country=$tld;
  65.     
  66.                 $country="<img src=img/countries/".strtolower($tld).".gif width=18 height=12 border=0 align=absmiddle hspace=4>".$country;
  67.                 }
  68.             print "<tr class=\"tbl2\"><td>".$LANG["country"]." (".$LANG["proxy"].")</td><td>".$country."</td></tr>\n";
  69.             }
  70.         print "<tr class=\"tbl2\"><td colspan=2><a href=\"index.php?st=log&stm=".$stm."&ftm=".$ftm."&sel_ip=2&inp_ip=".urlencode($ip)."&filter=".urlencode($filter)."\">".$LANG["viewlogforip"]." ".$ip."</a></td></tr>\n";
  71.                                                                                                                                                                      
  72.         print "</table><br>";
  73.         $a=array();
  74.         exec("whois -h whois.ripe.net ".(islocal($ip)?$proxy:$ip),$a);
  75.  
  76.         if (count($a)!=0) {
  77.             print $TABLE."<tr><td class=\"tbl1\" style=\"font-family:courier new;font-size:12px;\">";
  78.             for ($i=2;$i<count($a);$i++) {
  79.                 $do=1;
  80.                 if (substr($a[$i],0,4)=="chan")    $do=0;
  81.                 if (substr($a[$i],0,1)=="%")    $do=0;
  82.                 if ($do==1) print $a[$i]."<br>\n";
  83.                 }
  84.             print "</td></tr></table>\n";
  85.             }
  86.         }
  87.     else {
  88.         print $TABLE."<tr><td>";
  89.         print "No info.";
  90.         print "</td></tr></table>\n";
  91.         }
  92.  
  93.     }
  94. else {
  95.     print $TABLE."<tr><td>";
  96.     print "No info.";
  97.     print "</td></tr></table>\n";
  98.     }
  99. ?>
  100.