Manuel Pear

Introduction

Introduction -- Introduction to Net_DNSBL

Description

PEAR::Net_DNSBL provides an easy way to check if a given Host or URL is listed on an DNS-based Blackhole List (DNSBL, Real-time Blackhole List or RBL) or Spam URI Realtime Blocklist (SURBL).

Please not that this currently only works with IPv4 IPs.

Usage

Let's start with a simple example to check if the remote host is listed in two blacklists:

  1. <?php
  2. require_once 'Net/DNSBL.php';  
  3. $dnsbl = new Net_DNSBL();  
  4. $remoteIP = $_SERVER['REMOTE_ADDR'];  
  5. $remoteIP = '81.70.69.193';  
  6. $dnsbl->setBlacklists(array('sbl-xbl.spamhaus.org', 'bl.spamcop.net'));  
  7. if ($dnsbl->isListed($remoteIP)) { 
  8.    // do something
  9. }  
  10.  
  11. ?> 

This example shows how to check if an URL is listed in a SURBL:

  1. <?php
  2. require_once 'Net/DNSBL/SURBL.php';  
  3. $surbl = new Net_DNSBL_SURBL();  
  4. if ($surbl->isListed($addData['url'])) { 
  5.    // do something
  6. }  
  7.  
  8. ?> 
An example how to extract URLS from a text can be found on http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php and be used this way:
  1. <?php
  2. foreach ($extracted_urls as $surbl_check_url) { 
  3.    if ($surbl->isListed($surbl_check_url)) { 
  4.       // do something
  5.       break; 
  6.    }  
  7. }  
  8.  
  9. ?> 

Let's get some details, if our host is listed:

  1. <?php
  2. require_once 'Net/DNSBL.php';  
  3. $dnsbl = new Net_DNSBL();  
  4. $dnsbl->setBlacklists(array('sbl-xbl.spamhaus.org', 'bl.spamcop.net'));  
  5. if ($dnsbl->isListed($_SERVER['REMOTE_ADDR'])) {  
  6. var_dump($dnsbl->getDetails($_SERVER['REMOTE_ADDR']));  
  7. var_dump($dnsbl->getTxt($_SERVER['REMOTE_ADDR']));  
  8. var_dump($dnsbl->getListingBl($_SERVER['REMOTE_ADDR']));  
  9. var_dump($dnsbl->getListingRecord($_SERVER['REMOTE_ADDR']);  
  10. }  
  11.  
  12. ?> 

Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique