Witam, napisałem skrypt pobierający (wyr. regularne) informacje ze strony RIPE.NET/WHOIS smile.gif

Skrypt pobiera:
Pulę adresów dla danego miejsca
Nazwę dostawcy internetu
Kraj, do którego należy dany IP
Miasto

UWAGA! Należy dograć flagi (np. pl.gif) do katalogu flagi/ w głównym folderze skryptu. Znaleźć je można np. na cs.pl

  1. <?php
  2. $cities = array('Wroclaw' => 'Wrocław', 
  3. 'Rzeszow' => 'Rzeszów', 
  4. 'Krakow' => 'Kraków', 
  5. 'Poznan' => 'Poznań', 
  6. 'Kolobrzeg' => 'Kołobrzeg'
  7. );
  8.  
  9. $ip = ($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR'];
  10.  
  11. $url = 'http://ripe.net/fcgi-bin/whois?form_type=advanced&full_query_string=&searchtext='.$ip;
  12. $url.= '&inverse_attributes=None&ip_search_lvl=Default&recursive=ON&domain_name_referral=ON';
  13. $url.= '&alt_database=RIPE&object_type=domain&object_type=inet6num&object_type=inetnum';
  14. $url.= '&Simple+search=Simple+search';
  15.  
  16. $file = file($url);
  17. $read = implode(&#092;"\", $file);
  18. $read = str_replace(&#092;"r\", \"\", $read);
  19. $read = str_replace(&#092;"n\", \"!nline!\", $read);
  20.  
  21. if(preg_match('#<pre><b><u>inetnum</u></b>:(.*?)</pre>#', $read, $zmienna))
  22. {
  23.  $a = $zmienna[1];
  24.  $a = str_replace(&#092;"!nline!\", \"n\", $a);
  25.  $a = strip_tags($a);
  26.  
  27.  $b = explode(&#092;"n\", $a);
  28.  foreach($b as $line)
  29.  {
  30. $line = str_replace(&#092;"  \", \"\", $line);
  31. $line = preg_replace(&#092;"#(.*?):#\", \"\", $line);
  32.  
  33. $ab[] = $line;
  34.  }
  35.  
  36.  $info['inetnum'] = $ab[0];
  37.  $info['ispname'] = $ab[2];
  38.  $info['city'] = $ab[3];
  39.  $info['country'] = $ab[4];
  40.  
  41.  function strip_space($txt)
  42.  {
  43. if($txt{0} == &#092;" \")
  44. {
  45.  $txt = substr($txt, 1);
  46.  $txt = strip_space($txt);
  47. }
  48. return $txt;
  49.  }
  50.  
  51.  $info['inetnum'] = strip_space($info['inetnum']);
  52.  $info['ispname'] = strip_space($info['ispname']);
  53.  $info['city'] = strip_space($info['city']  );
  54.  $info['country'] = strip_space($info['country']);
  55.  
  56.  if(file_exists('flagi/'.strtolower($info['country']).'.gif'))
  57.  {
  58. $flag = '<img src=\"flagi/'.strtolower($info['country']).'.gif\" border=\"0\">';
  59.  }
  60.  else
  61.  {
  62. $flag = '<img src=\"flagi/na.gif\" border=\"0\">';
  63.  }
  64.  
  65.  foreach($cities as $cit => $pl)
  66.  {
  67. $info['city'] = str_replace($cit, $pl, $info['city']);
  68.  }
  69.  
  70.  echo '<p style=\"font-family:Verdana; font-size:10px;\">';
  71.  echo '<b>Pula adresów:</b> '.$info['inetnum'].'<br />';
  72.  echo '<b>Dostawca internetu:</b> '.$info['ispname'].'<br />';
  73.  echo '<b>Kraj i miasto:</b> '.$flag.' '.$info['city'].'</p>';
  74.  
  75. }
  76. ?>


Przykład użycia:
  • Link: index.php?ip=83.27.66.241
Kod można dowolnie modyfikować.... jest w stanie zwrócić wszystkie informacje wyświetlane przez ripe.net smile.gif