Page : | [ 1 ] | [ 2 ] |
Here's the simple script to harvest the IP's for the domains we are interested in:
<?php
ini_set('display_errors',0);
error_reporting(0);
define('DBHOST', 'yourDatabaseHost');
define('DBUSER', 'yourDatabaseUser');
define('DBPASS', 'yourDatabasePassword');
define('DATABASE', 'YourDatabaseName');
$db = new mysqli(DBHOST, DBUSER, DBPASS, DATABASE);
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
$db->query("SET NAMES 'utf8'");
//////////////////////////////////////////////////
// Gets the domains from PIA
//////////////////////////////////////////////////
$dat = file_get_contents('https://www.privateinternetaccess.com/pages/network/');
$dom = new DomDocument();
$dom->loadHTML($dat);
$tds = $dom->getElementsByTagName('td');
$hosts = array();
foreach ($tds as $tdkey => $td){
$value = $td->nodeValue;
$pos = strpos($value, '.privateinternetaccess.com');
if ($pos !== false){
$parent = $td->parentNode;
if ($parent->tagName == 'tr'){
$childs = $parent->childNodes;
$count = $childs->item(4)->nodeValue;
$host = $childs->item(0)->nodeValue;
if (substr($host,0, 3) == 'us-'){
$hosts[$host] = array($count, $host);
}
}
}
}
//////////////////////////////////////////////////
// Insert the hosts into the DB
//////////////////////////////////////////////////
foreach ($hosts as $hkey => $host){
$query = " insert into domain (domainName, ipCount) values (";
$query .= " '" . $db->real_escape_string(trim($host[1])) . "' ";
$query .= " ," . intval($host[0]) . ") ";
$db->query($query);
}
$domains = array();
$query = " select * from domain order by domainId ";
if ($result = $db->query($query)) {
if ($result->num_rows > 0){
while ($row = $result->fetch_assoc()){
$domains[] = $row;
}
}
}
$count = 0;
//////////////////////////////////////////////////
// Endlessly query the nameserver
//////////////////////////////////////////////////
while(1){
echo "\n\n\n";
foreach ($domains as $dkey => $domain){
echo "\nProcessing for " . $domain['domainName'] . "\n";
$outputs = array();
exec('/usr/bin/dig +nocmd +noall +answer ' . $domain['domainName'] . ' @ns1.p28.dynect.net', $outputs);
foreach ($outputs as $okey => $output){
$match = array();
if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $output, $match)) {
$valid = filter_var($match[0], FILTER_VALIDATE_IP);
if ($valid){
echo $match[0];
$query = " insert into ip (domainId, ipAddress) values (";
$query .= " " . intval($domain['domainId']) . " ";
$query .= " ,'" . $db->real_escape_string($match[0]) . "') ";
$db->query($query);
echo " " . $match[0] . "\n";
}
}
}
echo "\n";
}
echo "\n";
echo 'Iteration : ' . ++$count;
echo "\n\n";
sleep(1);
}
?>
At this point you should have a table full of IP's for each of the domains. Now do something useful with them :)
This is only useful if you NEED to know the individual IP's. Most usage scenarios it would be sufficient to use the domain name and get a random IP via DNS.
(Page 2 of 2) | ||