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.py
chmod u+x ~/bin/resetear.py
El script es el siguiente:
#!/usr/bin/python
#
# Copyright (C) 2012 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 40s. In this example use default values for jazztel .
import getpass
import sys
import telnetlib
import time
import urllib2
import re
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""
def resetear():
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()
return
def getip():
try:
ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}' ,urllib2.urlopen('http://checkip.dyndns.org/').read())
salida = ip[0];
except:
salida = '(Error al obtener la ip)'
return salida
#programa
ip_current = getip()
print 'Current ip -> ' + ip_current
resetear()
ip_new = getip()
print 'New ip -----> ' + ip_new
No hay comentarios:
Publicar un comentario