• Welcome to Hurricane Electric's IPv6 Tunnel Broker Forums.

Anything wrong with scripting?

Started by imduffy, June 06, 2010, 07:28:11 PM

Previous topic - Next topic

imduffy

Hi, for those of us thats lazy, I was wondering if there is anything wrong with just writing a script to do the daily whoises, digs, traceroutes, pings etc.

where querying the mysql db is just a list of IPv6 hostnames and domains.

e.g.


<?php
function he($username$password)
{
    
    
    
$con mysql_connect("localhost","mysqluser","mysqlpass");
    if (!
$con)
    {
        die(
'Could not connect: ' mysql_error());
    }
    
    
mysql_select_db("mysqldb"$con);
    
    
$query mysql_query("SELECT * FROM IPv6");
    
$row mysql_fetch_row($query);
    
    
$id $row[0];
    
$host escapeshellcmd(base64_decode($row[1]));
    
$ip escapeshellcmd(base64_decode($row[2]));
    
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL'http://ipv6.he.net/certification/login.php');
    
curl_setopt($chCURLOPT_POSTFIELDS,'f_user='.urlencode($username).'&f_pass='.urlencode(md5($password))).'&Login=Login';
    
curl_setopt($chCURLOPT_POST1);
    
curl_setopt($chCURLOPT_HEADER0);
    
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    
curl_setopt($chCURLOPT_COOKIEJAR"my_cookies.txt");
    
curl_setopt($chCURLOPT_COOKIEFILE"my_cookies.txt");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
    
curl_exec($ch);
    
    
    
curl_setopt($chCURLOPT_URL"http://ipv6.he.net/certification/whois.php");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$data = array(
    
'whoistext' => shell_exec("whois $ip"),
    
'submit' => 'Submit',
    );
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    echo 
curl_exec($ch);
    
    
curl_setopt($chCURLOPT_URL"http://ipv6.he.net/certification/ping.php");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$data = array(
    
'pingtext' => shell_exec("ping6 $ip -c 3"),
    
'submit' => 'Submit',
    );
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    echo 
curl_exec($ch);
    
    
    
curl_setopt($chCURLOPT_URL"http://ipv6.he.net/certification/dig2.php");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$data = array(
    
'digtext' => shell_exec("dig -x $ip PTR"),
    
'submit' => 'Submit',
    );
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    echo 
curl_exec($ch);
    
    
    
curl_setopt($chCURLOPT_URL"http://ipv6.he.net/certification/dig.php");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$data = array(
    
'digtext' => shell_exec("dig $host AAAA"),
    
'submit' => 'Submit',
    );
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    echo 
curl_exec($ch);
    
    
curl_setopt($chCURLOPT_URL"http://ipv6.he.net/certification/daily_trace.php");
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_POSTtrue);
    
$data = array(
    
'trtext' => shell_exec("traceroute -6 $ip"),
    
'submit' => 'Submit',
    );
    
curl_setopt($chCURLOPT_POSTFIELDS$data);
    echo 
curl_exec($ch);
    
    
    
mysql_query("DELETE FROM IPv6 WHERE ID='$id'");
}
?>


broquea

I don't see anything wrong with it. We don't detect user_agent or anything.

cholzhauer

Sure would have been easier on me if you would have posted that script a couple months ago ;)

mindlesstux

The script looks handy... question though, what is your database scheme look like?

imduffy

For the Database I just made a table with the fields ID host ip and then used the following script to populate it


<?php
$con 
mysql_connect("localhost","mysquser","mysqlass");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("mysqldb"$con);


$xml simplexml_load_file("http://sixy.ch/feed");

foreach(
$xml->entry as $entry) {
$title base64_encode($entry->title);
$ip base64_encode(shell_exec("dig $entry->title AAAA +short"));
if(
$ip != ""mysql_query("INSERT INTO `IPv6` (`ID`, `Host`, `IP`) VALUES (NULL, '$title', '$ip')");
}

?>