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

  • Home
  • SEARCH
  • 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 6595445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:56:26+00:00 2026-05-25T17:56:26+00:00

I am new to python, I am writing a script to ‘telenet’ device IP

  • 0

I am new to python, I am writing a script to ‘telenet’ device IP in some cases and SSH username@deviceIp if telnet faiils..

For all Telnet IP’s it work perfectly.. But when i am doing “ssh admin@153.88.127.21” the below code fails and I get error in try bloc itself like “socket.error” for ssh device’s.

I want ssh devices to enter else block,, if telnet Ip fails in try block.

In my Main.py file

    try:
        #TELNET MODULE CALL
        tn= _telnetMOD._telnet(username, password, device)
        break
    else:
        #SSH MODULE CALL
        ssh= _sshMOD._ssh(username, password, device)

In _telnetMod file i have below code which works
import telnetlib

def _telnet(_userVar,_passwordVAR, _device):
    tn=''
    tn = telnetlib.Telnet(_device,23)
    #PYTHON VERSION 2.6 AND HIGHER
    tn.read_until("Username: ",10)
    tn.write(_userVar + "\r")
    if _passwordVAR:
        tn.read_until("Password: ",10)
        tn.write(_passwordVAR + "\r")    
    return tn

In _sshMOD file i have below code which fails and not sure of below code

import paramiko 

def _ssh(_userVar,_passwordVAR, _device):
    ssh=''
    ssh= paramiko.SSHClient()
    ssh.connect(_device, username=_userVar,password=_passwordVAR)
    return ssh
  • 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-05-25T17:56:27+00:00Added an answer on May 25, 2026 at 5:56 pm

    Did you forgot the client.load_system_host_keys()? This is an example from the docs:

    client = SSHClient()
    client.load_system_host_keys()
    client.connect('ssh.example.com')
    stdin, stdout, stderr = client.exec_command('ls -l')
    

    And you should use the try block like this:

    try:
        telnet()
    except:
        telnet = false
    if telnet == false:
        try:
            ssh()
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python and am writing some scripts to automate downloading files
I am new to Python, and I'm working on writing some database code using
Hey guys/gals I'm writing a python script that fixes some duplicate issues on my
I am writing a python script that will be doing some processing on text
I am currently writing a Python script and trying to dynamically generate some arguments.
I'm really new to C -> Python interaction and am currently writing a small
I'm writing a python script to read through a list of domains, find out
I am writing a short python script for fun to check a few pages
I'm writing a Python-based shell script to boilerplate a Django app with virtualenv, pip,
I'm writing a python script to replace strings from a each text file in

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.