What does “\r” do in the following script?

后端 未结 4 946
傲寒
傲寒 2020-11-28 11:09

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\         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 11:37

    \r is the ASCII Carriage Return (CR) character.

    There are different newline conventions used by different operating systems. The most common ones are:

    • CR+LF (\r\n);
    • LF (\n);
    • CR (\r).

    The \n\r (LF+CR) looks unconventional.

    edit: My reading of the Telnet RFC suggests that:

    1. CR+LF is the standard newline sequence used by the telnet protocol.
    2. LF+CR is an acceptable substitute:

    The sequence "CR LF", as defined, will cause the NVT to be positioned at the left margin of the next print line (as would, for example, the sequence "LF CR").

提交回复
热议问题