Search code examples
pythonpython-3.xtelnetlib

Are my telnetlib imports wrong?


Been having an issue with this code:

    from telnetlib import Telnet

class doTelnet:

def login(self):
        # Configure login variables for input
        self.user = self.user.encode('ascii') + b'\n'
        self.password = self.password.encode('ascii') + b'\n'
        self.terminal_type = self.terminal_type.encode('ascii') + b'\n'

        # Do login
        # TODO Add functionality for user control of expected login prompt (some servers send 'Username: ', I'm sure theres other options)
        self.telnet.read_until('login: ')
        self.telnet.write(self.user)
        self.telnet.read_until('Password: ')
        try:
            self.telnet.write(self.password)
            print('[*]\tSuccessfully authenticated to {0}:{1}'.format(self.host, self.port))
            self.login_status = 1
        except Exception as self.e:
            print('[!]\tError authenticating to {0}:{1}\n{2}'.format(self.host, self.port, self.e)

        # Set terminal type
        self.telnet.write(self.terminal_type)

It consistently fails on the "self.telnet.write" section, which I can't understand why that might be. Anyone a wizard?

File "C:\Users\user\Downloads\CiscoIOSSNMPToolkit\doTelnet.py", line 45
    self.telnet.write(self.terminal_type)
       ^
SyntaxError: invalid syntax

Is the error.

https://github.com/GarnetSunset/CiscoIOSSNMPToolkit/blob/master/doTelnet.py


Solution

  • You are missing a parenthesis at the end of your print statement in the exception block which is why you are throwing your current syntax error.