我正在使用以下脚本通过 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 + "\n\r")
sleep(1)
tn.read_until("Password: ")
tn.write(password + "\n\r")
sleep(1)
tn.write(cmd + "\n\r")
我不知道为什么,但是移除 "\r"
就会破坏这段代码。那么在这个脚本中 "\r"
是用来做什么的?通常什么情况下需要使用 "\r"
?
注意:我知道“回车符”,但仍然无法弄清楚它在我的脚本中的用途。我正在 Linux 中运行此脚本。