#!/usr/bin/env python # -*- coding: UTF-8 -*- # # this program change dynamic ip if you using livebox (orange) wireless router # Copyright (C) 2010 Jakub Jankiewicz (jcubic@onet.pl) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import base64 import urllib2 import urllib from getopt import getopt from sys import argv from os.path import basename 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) if __name__ == '__main__': usage = """this script change your ip adress if you using livebox top usage: %s -p -h default password is 'admin' default host is 192.168.1.1 """ % basename(argv[0]) 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" else: print usage