I am using following script to reboot my router using Telnet:
#!/usr/bin/env python
import os
import telnetlib
from time import sleep
host = "192.168.1.1"
user = "USER"
password = "PASSWORD"
cmd = "system restart"
tn = telnetlib.Telnet(host)
sleep(1)
tn.read_until("Login: ")
tn.write(user + "
")
sleep(1)
tn.read_until("Password: ")
tn.write(password + "
")
sleep(1)
tn.write(cmd + "
")
I don't know why but removing "
" from above code make the script non-working. So what does "
" do in this script and when to use "
" in general?
Note: I know about "Carriage Return" but still could not figure out its use in my script. I am running this script in Linux.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…