Change you 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.

#!/usr/bin/python
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)
    return request.read()

def disconnect(host, passwd):
    "disconnect from internet."
    data = {'ACTION_DISCONNECT': 'Rozłącz'}
    return send(data, host, passwd)

def connect(host, passwd):
    "connect to the internet."
    data = {'ACTION_CONNECT': 'Połącz'}
    return send(data, host, passwd)

You can use this functions like this.

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', '192.168.1.1')
        try:
            disconnect(host, passwd)
            connect(host, passwd)
        except urllib2.HTTPError, e:
            if e.code == 401:
                print 'wrong password'
            else:
                print 'Error: %s' % e.args
            exit(1)
        except urllib2.URLError, e:
            print 'Error: %s' % ' '.join(e.args)
        else:
            print "password successfuly changed"

You could use this progam like this:

change_ip.py -h <your host> -p <your password>

Default host is 192.168.1.1 and default password is admin

Programming Blogs - Blog Catalog Blog Directory

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: