comtrend hg536+: cambiar de ip sin resetear el router, script en python
El siguiente código contiene un script en python para resetear el router comtrend hg536+, en este caso está configurado para un router jazztel con los valores por defecto de user,pass y el nombre de la conexión.
El script usa lo mismo que lo explicado en Comtrend hg536+: cambiar de ip sin resetear el router.
Podremos ejecutarlo siempre y cuando tengamos instalado python en nuestro SO (linux, windows ...). Podemos crear el archivo con el comando
cat > ~/bin/resetear.pyVersión actualizada en :
chmod u+x ~/bin/resetear.py
http://dieguz2.blogspot.com.es/2012/04/comtrend-hg536-script-para-cambiar-de.html
El script es el siguiente:
#!/usr/bin/python
#
# Copyright (C) 2009 dieguz2
# License: GNU GPL v2
# http://dieguz2.blogspot.com/
# Script for comtrend hg536+ ( firmware A101-302JAZ-C03_R21.A2pB021g.d15h )
# This scripts connect to router and reset ip in 45s. In this example use default values for jazztel .
import getpass
import sys
import telnetlib
import time
HOST = "192.168.1.1"
LOGIN = "admin"
PASS = "admin"
PROMPT = " -> "
WAITTIME = 40 # Number of second
CONNECTIONNAME = "0.8.35 2" # to see your connections, manually connect to router (telnet 192.168.1.1) and use "wan show" .You should choose you PPPoE connection Use a combination of VCC + Con Id. For example ""0.8.35 2""
tnt = telnetlib.Telnet(HOST)
tnt.read_until("Login: ")
tnt.write(LOGIN + "\n")
tnt.read_until("Password: ")
tnt.write(PASS + "\n")
tnt.read_until(PROMPT)
tnt.write("ppp config " + CONNECTIONNAME + " down\n")
time.sleep(3)
tnt.write("\n")
tnt.write("ppp config " + CONNECTIONNAME + " up\n")
time.sleep(WAITTIME)
tnt.read_until(PROMPT)
tnt.write("ppp config " + CONNECTIONNAME + " up\n")
tnt.write("\n")
tnt.read_until(PROMPT)
tnt.write("13\n") # press option to exit
tnt.close()
Comentarios
Lástima que Jazztel tarde tanto en proveer una nueva IP, cuando tenía telefonica tardaba menos de 5 segundos en cambiarla.
Pero bueno, merece la pena esperar un poco más por lo que se ahorra de pasta.