Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:58:56+00:00 2026-06-18T00:58:56+00:00

I am using following script to reboot my router using Telnet: #!/usr/bin/env python import

  • 0

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 + "\n\r")
sleep(1)

tn.read_until("Password: ")
tn.write(password + "\n\r")
sleep(1)

tn.write(cmd + "\n\r")

I don’t know why but removing "\r" breaks this code. So what does "\r" do in this script and when do I use "\r" in general?

Note: I know about "Carriage Return" but still could not figure out it is used in my script. I am running this script in Linux.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:58:56+00:00Added an answer on June 18, 2026 at 12:58 am

    The '\r' character is the carriage return, and the carriage return-newline pair is both needed for newline in a network virtual terminal session.


    From the old telnet specification (RFC 854) (page 11):

    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").

    However, from the latest specification (RFC5198) (page 13):

    1. …

    2. In Net-ASCII, CR MUST NOT appear except when immediately followed
      by either NUL or LF, with the latter (CR LF) designating the "new
      line" function. Today and as specified above, CR should
      generally appear only when followed by LF. Because page layout
      is better done in other ways, because NUL has a special
      interpretation in some programming languages, and to avoid other
      types of confusion, CR NUL should preferably be avoided as
      specified above.

    3. LF CR SHOULD NOT appear except as a side-effect of multiple CR LF
      sequences (e.g., CR LF CR LF).

    So newline in Telnet should always be '\r\n' but most implementations have either not been updated, or keeps the old '\n\r' for backwards compatibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following script : #!/bin/bash #script to print quality of man #unnikrishnan
I'm using the following script from phpmyadmin in a shared hosting: USE newmakerting CREATE
I'm using the following script to move a <tr> from any position in a
I've tried to change filenames using following script: find dir/ -type f -exec mv
I'm using the following script in my website in order to create pagination next-previous
I'm using the following script to request new content to a file called index.html:
I'm using the following script to force a specific page - when loaded for
I am currently using the following script to set this value as a String:
I'm using the following script for a window.onload custom radio button replacement (http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/custom-form-elements.js) and
I am using the following script to upload pictures to my website. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.