login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Handige scripts > RIPE whois functie

RIPE whois functie

Auteur: Gerard - 03 mei 2005 - 16:12 - Gekeurd door: CelestialCelebi - Hits: 6134 - Aantal punten: 2.67 (3 stemmen)



Een script wat bij mij gebruikt is op een vBulletin 2 installatie om verbinding te maken met RiPE om zo meer informatie op te halen over een bepaald ip-adres.

Kan handig zijn voor normale websites of voor ip-lookups van members.

Deze snippet zoekt alleen de lijnen uit die voor mij interressant waren. Het kan natuurlijk altijd zo zijn dat jij iets meer informatie wil. Je kan dan gewoon de for loop aanpassen.

Update 12-03-2007
Ik zat eens door mijn zelfgemaakte (en gedeelde) scripts hier op sitemasters te bladeren en zag dat ik dit stukje onzin ooit een keer had gemaakt. Natuurlijk script ik tegenwoordig al lang niet meer zo en dus vond ik het dus wel zo netjes om hem even bij te werken en in een functie te gieten.

De documentatie spreekt voor zich. Mocht je echter vragen/opmerkingen hebben dan hoor ik deze graag.

Code:
  1. <?php
  2.  
  3. /**
  4.   * The function can be used to extract information from the RIPE whois database
  5.   * about an ip address. The function is capable of filtering the data to supply
  6.   * you with only the information that you want. Further more it can return an
  7.   * array with each part of the information in a seperate key or return a string
  8.   * with all the requested information.
  9.   *
  10.   * @author Gerard Klomp <glj.klomp@googlemail.com>
  11.   * @version 1.0
  12.   * @param string $sIpAddress The ip address to retrieve more information about
  13.   * @param boolean $bReturnArray Set to true to return an array, else it will return a string (default: true)
  14.   * @param array $aGetValuesOf Lists all the keys to retrieve
  15.   * @return array|string|boolean Returns array|string on success, else false
  16.   */
  17.  
  18. function ripe_whois($sIpAddress, $bReturnArray = true, $aGetValuesOf = array('inetnum', 'netname', 'descr', 'country', 'org')) {
  19.  
  20. $rConnection = fsockopen('whois.ripe.net', 43, $iErrNo, $sErrStr, 5);
  21.  
  22. if ($rConnection) {
  23.  
  24. $aReturn = array();
  25. $sResult = '';
  26.  
  27. fwrite($rConnection, $sIpAddress . "\n");
  28.  
  29. while (true) {
  30.  
  31. if (strlen(($sData = fread($rConnection, 8192))) == 0) {
  32. break;
  33. }
  34.  
  35. $sResult .= $sData;
  36.  
  37. }
  38.  
  39. fclose($rConnection);
  40.  
  41. foreach(explode("\n", $sResult) as $sResultRow) {
  42.  
  43. $sResultRow = trim($sResultRow);
  44.  
  45. if (ereg('%', $sResultRow) === false && !empty($sResultRow) && ereg(implode('|', $aGetValuesOf) . ':', $sResultRow) !== false && $bReturnArray) {
  46. $aRow = explode(':', $sResultRow, 3);
  47. $aReturn[$aRow[0]] = (isset($aReturn[$aRow[0]]) ? $aReturn[$aRow[0]] . "\n" . trim($aRow[1]) : trim($aRow[1]));
  48. $aReturn[$aRow[0]] = (isset($aRow[2]) ? $aReturn[$aRow[0]] . ":" . trim($aRow[2]) : $aReturn[$aRow[0]]);
  49. } else if (ereg('%', $sResultRow) === false && !empty($sResultRow) && ereg(implode('|', $aGetValuesOf) . ':', $sResultRow) !== false && !$bReturnArray) {
  50. $aReturn[md5($_SERVER['REMOTE_ADDR'])] .= "\n" . $sResultRow;
  51. }
  52.  
  53. }
  54.  
  55. return ($bReturnArray ? $aReturn : trim($aReturn[md5($_SERVER['REMOTE_ADDR'])]));
  56.  
  57. }
  58.  
  59. return false;
  60.  
  61. }
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (2)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.026s