Script for reconnect adsl in d-link router

In work I have wireless network with D-Link router “DSL-2640B”, and I need to reconnect ADSL service to change IP adress, so I write this ruby script, which use telnet standard libary.

require 'net/telnet'
require 'optparse'

opts = ARGV.getopts('h:p:')

passwd = opts['-p']
host = opts['-h']

server = Net::Telnet::new('Host'=>host,
                          'Port'=> 23,
                          'Prompt'=> />/)
server.cmd("adsl connection --down")
server.cmd("adsl connection --up")

You can use it in terminal by typing:

reconnect.rb -p <password> -h <host>

You must wait couple of seconds before your d-link router connect to ADSL.

Get you livebox router IP Adres

Here is bash on alias for get IP adress of your livebox router. (tested on Ubuntu GNU/Linux)

alias livebox-ip='tmp=`mktemp`;curl -u admin:<your password> --silent --url -o $tmp; grep -E "var v_Adrs_IP[^=]*=" $tmp | cut -d"\"" -f2 ; rm $tmp'

You must have installed curl. Note that you must change your livebox password.

Change your IP with livebox

If you have livebox wireless router you could easily change you dynamic IP. It is handy if you download files from rapidshare. Here is the python code. It was tested on polish livebox. You could download code from here.

import base64
import  urllib2
import urllib

def send(data, host, passwd):
    "send request to livebox SubmitInternetService."
    action = 'http://%s/SubmitInternetService' % host
    req = urllib2.Request(action, urllib.urlencode(data))
    passwd = base64.b64encode('%s:%s' % ('admin', passwd))
    req.add_header('Authorization',  'Basic %s' % passwd)
    request = urllib2.urlopen(req)

def disconnect(host, passwd):
    "disconnect from internet."
    data = {'ACTION_DISCONNECT': 'Roz<span>&</span>#322;<span>&</span>#261;cz'}
    return send(data, host, passwd)

def connect(host, passwd):
    "connect to the internet."
    data = {'ACTION_CONNECT': 'Po<span>&</span>#322;<span>&</span>#261;cz'}
    return send(data, host, passwd)</pre>
You can use this functions like this.
<pre>if __name__ == '__main__':
    from sys import argv
    opts, rest = getopt(argv[1:], 'p:h:')
    opts = dict(opts)
    if len(rest) == 0:
        passwd = opts.get('-p', 'admin')
        host = opts.get('-h', '')
            disconnect(host, passwd)
            connect(host, passwd)
        except urllib2.HTTPError, e:
            if e.code == 401:
                print 'wrong password'
                print 'Error: %s' % e.args
        except urllib2.URLError, e:
            print 'Error: %s' % ' '.join(e.args)
            print "password successfuly changed"

You could use this progam like this: -h <your host> -p <your password>

Default host is and default password is admin