Python Telnet connection

强颜欢笑 提交于 2019-11-28 21:37:23

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

The docs in this link: http://docs.python.org/library/telnetlib.html

It has a sample code at the end under the section "Telnet Example".

You can access the example via: http://docs.python.org/library/telnetlib.html#telnet-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!