Python Telnet connection

Lol, i had pretty much the same router as you.

Try this, bit of my old code:

tn = telnetlib.Telnet(HOST)

tn.read_until('Username : ')

tn.write(user+ "\r")

tn.read_until("Password : ")

tn.write(password+ "\n")

tn.write("\r")

This is for Python 2, but try just adding the extra space after the semicolon. Also, if this does not work, use wireshark and see what the putty connection is doing and correct your code to match.


# Script to Telnet in to a host
# For now I have hardcoded the HOST that can be taken as input if required
#run as " python teli.py ""

import time
import telnetlib
HOST ="www.google.com"
tn=telnetlib.Telnet(HOST,"80")
tn.write("GET /index.html HTTP/1.1\nHost:"+HOST+"\n\n")
l=tn.read_all()
print l

Tags:

Python

Telnet