Hurricane Electric's IPv6 Tunnel Broker Forums
May 23, 2013, 07:34:11 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to Hurricane Electric's Tunnelbroker.net forums!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Anything wrong with scripting?  (Read 3106 times)
imduffy
Newbie
*
Posts: 4



View Profile WWW
« on: June 06, 2010, 07:28:11 pm »

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.

Code:
<?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'");
}
?>

« Last Edit: June 08, 2010, 05:16:43 pm by imduffy » Logged

broquea
Senior Network Engineer, SEVEN Networks (AS19733)
Hero Member
*****
Posts: 1378



View Profile WWW
« Reply #1 on: June 06, 2010, 07:42:26 pm »

I don't see anything wrong with it. We don't detect user_agent or anything.
Logged
cholzhauer
Hero Member
*****
Posts: 2082


View Profile
« Reply #2 on: June 06, 2010, 09:31:37 pm »

Sure would have been easier on me if you would have posted that script a couple months ago Wink
Logged
mindlesstux
Newbie
*
Posts: 33



View Profile WWW
« Reply #3 on: June 07, 2010, 08:48:34 am »

The script looks handy... question though, what is your database scheme look like?
Logged
imduffy
Newbie
*
Posts: 4



View Profile WWW
« Reply #4 on: June 07, 2010, 09:37:07 am »

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

Code:
<?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')");
}

?>

Logged

gavinchappell
Newbie
*
Posts: 4


View Profile
« Reply #5 on: November 04, 2010, 03:00:10 am »

Hi,
I know I'm bumping an old thread, but I came across this one when I was looking through through the forums to work out whether this was "allowed" by HE.net or frowned upon. I decided that I would also try and script a daily run of this (since the tests are about your ability to actually maintain the IPv6 tunnel connection, rather than your ability to type some commands!), and have come up with a slightly simpler way which doesn't rely on having PHP installed or running a MySQL instance. I thought I'd paste it here, it might be useful for people with lower spec boxes, and if your router has curl and DNS tools installed (most third party firmwares such DD-WRT, Tomato, OpenWRT etc do I believe) then you might not even need a machine to run it on at all, it could be totally contained in your router. The IPv6 addresses used are the current IPv6 address for ipv6.he.net, this may change in the future. I've used HE.net so that it's a simpler test, testing things like ipv6.google.com introduces elements outside of my/HE's control (i.e. it also relies on the connection between HE and Google being operational, and if it's not then it could cause the test to fail even though there's nothing wrong with my tunnel).

Code:
#!/bin/bash
if [ ! -d ~/henet ]; then
        mkdir ~/henet
fi

traceroute6 ipv6.he.net > ~/henet/daily_traceroute || exit 1
dig aaaa ipv6.he.net > ~/henet/daily_aaaa || exit 1
dig -x 2001:470:0:64::2 > ~/henet/daily_ptr || exit 1
ping6 -n -c 4 ipv6.he.net > ~/henet/daily_ping || exit 1
whois 2001:470:0:64::2 > ~/henet/daily_whois || exit 1

# Do login to he.net with curl, storing cookies for later
curl -c ~/henet/cookies.txt -d "f_user=<USERNAME>&f_pass=<MD5SUM OF PASSWORD>" https://ipv6.he.net/certification/login.php

# Submit daily stuff
curl -q -s -b ~/henet/cookies.txt --data-urlencode trtext@/home/gavin/henet/daily_traceroute https://ipv6.he.net/certification/daily_trace.php
curl -q -s -b ~/henet/cookies.txt --data-urlencode digtext@/home/gavin/henet/daily_aaaa https://ipv6.he.net/certification/dig.php
curl -q -s -b ~/henet/cookies.txt --data-urlencode digtext@/home/gavin/henet/daily_ptr https://ipv6.he.net/certification/dig2.php
curl -q -s -b ~/henet/cookies.txt --data-urlencode pingtext@/home/gavin/henet/daily_ping https://ipv6.he.net/certification/ping.php
curl -q -s -b ~/henet/cookies.txt --data-urlencode whoistext@/home/gavin/henet/daily_whois https://ipv6.he.net/certification/whois.php
I've just tested this manually and it seems to work, I'm going to put it into cron to run at lunchtime tomorrow and see if it updates all 5 tests successfully. Please note that in the cURL command, "~/henet" didn't seem to work, I had to specify full paths to the files, or I got errors. YMMV.

To get the password string you need, then you can do the following (BE WARNED: this will show up in any history files used by your shell, for example .bash_history, and should be removed afterwards, or figure out the command to temporarily disable history before you run it)
Code:
echo -n password | md5sum

Cheers,
Gavin
« Last Edit: November 04, 2010, 03:32:32 am by gavinchappell » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!