[Linux-bruxelles] laptop : changement de configuration réseau ...
Olivier Laurent
oli at aragne.com
Mer 14 Avr 11:27:10 CEST 2004
On mer, 14 avr 2004, at 09:34, Didrik Pinte wrote:
> Bonjour,
>
> Je change de config réseau environ deux fois par jour (minimum). J'ai
> testé le package netenv mais sans succès (j'avoue que je n'ai pas pris
> le temps de bidouiller pour le faire tourner).
>
> Quelqu'un aurait-il une suggestion d'un package qui permet de faire ça ?
Non, mais j'ai créé un petit script Python qui fait çà très bien. Vois
en attachement.
Exemple: en étant 'root':
./netswitch.py chezmoi
--
Olivier Laurent.
P3B : Club Python(-Zope) Belge ---------- http://www.p3b.org
OS3B : Club Open-Software(-Linux) Carolo http://www.os3b.org
Aragne : Python-Zope Solutions & Formations http://www.aragne.com
-------------- section suivante --------------
#!/usr/bin/env python
import os, sys
usage="""usage: netswitch.py configuration_name"""
def _test():
try:
conf = sys.argv[1]
except IndexError:
print usage
sys.exit()
if conf == 'chezmoi':
os.system('ln -s -f /etc/hosts.CHEZMOI /etc/hosts')
os.system('ln -s -f /etc/resolv.conf.CHEZMOI /etc/resolv.conf')
os.system('ln -s -f /etc/network/interfaces.CHEZMOI /etc/network/interfaces')
os.system('/sbin/ifdown eth0')
os.system('/sbin/ifup eth0')
elif conf == 'auboulot':
os.system('ln -s -f /etc/hosts.AUBOULOT /etc/hosts')
os.system('ln -s -f /etc/network/interfaces.AUBOULOT /etc/network/interfaces')
os.system('ln -s -f /etc/resolv.conf.AUBOULOT /etc/resolv.conf')
os.system('/sbin/ifdown eth0')
os.system('/sbin/ifup eth0')
elif conf == 'chezunpote':
os.system('ln -s -f /etc/hosts.CHEZUNPOTE /etc/hosts')
os.system('ln -s -f /etc/network/interfaces.CHEZUNPOTE /etc/network/interfaces')
os.system('ln -s -f /etc/resolv.conf.CHEZUNPOTE /etc/resolv.conf')
os.system('/sbin/ifdown eth0')
os.system('/sbin/ifup eth0')
elif conf == 'dhcp':
os.system('ln -s -f /etc/hosts.DHCP /etc/hosts')
os.system('ln -s -f /etc/network/interfaces.DHCP /etc/network/interfaces')
os.system('ln -s -f /etc/resolv.conf.DHCP /etc/resolv.conf')
os.system('/sbin/ifdown eth0')
os.system('/sbin/ifup eth0')
else:
print "ERROR: This configuration doesn't exist"
print ":%s:" % conf
if __name__ == '__main__':
_test()
Plus d'informations sur la liste de diffusion Linux-bruxelles