0

I want to make a little script that returns me a result depending of how much a ip has been blacklisted.

Result must be like 23/100 means that 23 has blacklisted that ip or 45/100 2/100 ... and so on.

First of all i fetch trough CURL from http://whatismyipaddress.com/blacklist-check sending a post request some data :

<?php
/**
 * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
 * array containing the HTTP server response header fields and content.
 */

function get_web_page($url,$argument1)
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => "LOOKUPADDRESS=".$argument1,
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;
    $header['content'] = $content;
    return $header;
}

echo "<pre>";
$result = get_web_page("http://whatismyipaddress.com/blacklist-check","75.122.17.117");

// print_r($result['content']);
// in $result['content'] we have the whole pag


// Creating xpath and fill it with data
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTMLFile($result['content']); // loads your html
$xpath = new DOMXPath($doc);

// Get that table
$value = $xpath->evaluate("string(/html/body/div/div/div/table/text())"); 
echo "Table with blacklists: [$value]\n"; // prints your location



die;

?>

Now what i want is to parse the data with XPATH /html/body/div/div/div/table/text() and where i see the image (!) mark it as blacklisted, otherwise do nothing.

Can anyone help me?

I also observed that vewing the (!) image requires a token, i might switch to another site, but i like that particular website because it has all the websites.

Thank you!

hakre
  • 193,403
  • 52
  • 435
  • 836
Master345
  • 2,250
  • 11
  • 38
  • 50

1 Answers1

0

definitely you need this :) Simple DOM Parser

hakre
  • 193,403
  • 52
  • 435
  • 836
Marco
  • 842
  • 6
  • 18
  • 42
  • this is a class independent of PHP libraries ? – Master345 Sep 30 '12 at 14:43
  • @RowMinds yes it is its wonderful class make live much easier – Marco Sep 30 '12 at 14:46
  • this is one problem, i will parse easier with this, but look how a image link is `src=/blacklist_check.php?bl=web.dnsbl.sorbs.net&ip=78.96.118.160&token=89a5f0e88c2490ed2c53df8ec99725a1` it is not like `src=bad.png` ... – Master345 Sep 30 '12 at 14:48
  • That library is broken. I provided a link to a PHP library that's documented, working and supported: http://php.net/DomDocument Additinally browse the site for library suggestions, take those that are based on PHP's DomDocument, e.g. see http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php – hakre Sep 30 '12 at 20:19