Re: External scripts/code for NetworkManagerDispatcher collection.

On Tue, 2006-10-24 at 14:09 +0200, Stefan Schmidt wrote:
> Collect scripts and programs whcih communicate with nm or
> NetworkManagerDispatcher. There are so many cases which we don't like
> to handle direct in the nm code, but with external scripts.

Here is another one:
- Updates your (public) IP address in DynDNS

#!/usr/bin/env python
# Copyright (C) 2006 Saikat Guha <saikat cs cornell edu>
# 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 2 of the License, or any later version.

import dbus, socket, string, os
import httplib, urllib, base64
import pynotify

hostname = ""
username = "your_username"
password = "your_password"

def notify_dynupdate(error, host, ip = None):
    format = "<b>Host</b>: %(host)s\n<b>IP:</b> %(ip)s"
    text =  format % {"error" : "", "ip" : ip, "host" : host}
    if error is None:
        title = "DynDNS Updated"
        title = "DynDNS: %s" % error
    n = pynotify.Notification(title, text)

def get_error(resp, err = None):
    if resp == httplib.UNAUTHORIZED:
        return "Authorization failure"

def dynupdate(hostname, username, password):
    conn = httplib.HTTPConnection("")
    conn.request("GET", "/")
    resp = conn.getresponse()
    if resp.status == httplib.OK:
        data =
        ip = data.split(":")[1].split("<")[0].strip()
        conn = httplib.HTTPConnection("")
        params = urllib.urlencode({"system":"dyndns", "hostname":hostname, "myip":ip})
        headers = {"Authorization":"Basic "+base64.b64encode(username+":"+password),
        conn.request("GET", "/nic/update?" + params, "", headers)
        resp = conn.getresponse()
        data =
        result = data.split(" ")[0]
        if resp.status == httplib.OK:
            notify_dynupdate(None, hostname, ip)
            notify_dynupdate(get_error(resp.status), hostname, ip)
        notify_dynupdate("Cannot determine IP address", hostname, "unknown")

dynupdate(hostname, username, password)

Attachment: signature.asc
Description: This is a digitally signed message part

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]