Mar 122019

If like me you do not have a fixed IP addres, you may have to update a DNS record.

And if you use a VPN, you want to update the DNS record with your real IP address.

Here is a bootscript to do that in Python.

you need 2 things:

The address of the internet service which will display your IP
( in my case )

The gateway to use to directly connect to this service
( usually the default gateway when your are not connected through the VPN )

import socket
from pyroute2 import IPRoute

def set_route(dest, gw):
    resolver = socket.gethostbyname(dest)
    ip = IPRoute()
    get_to = ip.get_routes(dst=resolver)
    for f in get_to[0]['attrs']:
        if f[0] == 'RTA_GATEWAY':
            gw_curr = f[1]
            if gw_curr != gw:
                ip.route('add', dst=resolver, gateway=gw, mask=32)


This code will update the routes to bypass the VPN routes, and your DNS will be updated with the correct IP address.


 Publié par à 0 h 57 min

 Laisser un commentaire

Vous pouvez utiliser ces tags et attributs HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.