Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I make ddclient update my dyndns address whenever NetworkManager makes or cuts a connection?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

NetworkManager automatically calls scripts placed in /etc/NetworkManager/dispatcher.d with some interesting environment variables set. This is documented to some degree under man NetworkManager, but not all environment variables are explained there. I use a script like the one below, because i prefer the IP-Adress of the VPN-connection to be used on dyndns. The script also uses the last of multiple listed addresses, in the hope that it will be the most current, most important one.

#!/usr/bin/env python

import sys
import os
import subprocess

env = os.environ
n = int(env['IP4_NUM_ADDRESSES'])
nvpn = int(env.get('VPN_IP4_NUM_ADDRESSES',0))

if nvpn>0:
    ip = env['VPN_IP4_ADDRESS_'+str(nvpn-1)].split('/')[0]
else:
    ip = env['IP4_ADDRESS_'+str(n-1)].split('/')[0]

ret = subprocess.call(['/usr/sbin/ddclient', '-daemon=0', '-syslog', '-use=ip', '-ip='+ip])
sys.exit(ret)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.