如何创建匿名的Python telnet连接?

时间:2023-01-13 09:07:46

I am trying to telnet into a server using Python on Windows XP. I can connect successfully by typing 'telnet HOST PORT' which creates an anonymous connection. But Python's telnetlib.Telnet(HOST, PORT) returns 'Connection refused'. Telnetting in Java also fails. Spelunking shows that Python tries to create an anonymous socket connection. My admin says he doesn't allow anonymous connections. But neither Python nor Java allow authentication parameters to be passed in during socket connection creation (not that I could find). Why does Windows' command-line telnet work when Python and Java both fail? Any advice?

我试图在Windows XP上使用Python远程登录到服务器。我可以通过输入'telnet HOST PORT'来成功连接,这会创建一个匿名连接。但Python的telnetlib.Telnet(HOST,PORT)返回'Connection refused'。 Java中的Telnet也失败了。 Spelunking显示Python尝试创建匿名套接字连接。我的管理员说他不允许匿名连接。但是Python和Java都不允许在套接字连接创建期间传递身份验证参数(不是我能找到的)。当Python和Java都失败时,为什么Windows的命令行telnet有效?任何建议?

2 个解决方案

#1


It would be a good idea to trace both connection attempts (a failing case and a successful case) with wireshark or similar packet trace tool to see what the difference is at the protocol level.

使用wireshark或类似的数据包跟踪工具跟踪连接尝试(失败案例和成功案例)是一个好主意,以查看协议级别的差异。

#2


First, eliminate telnetlib as your problem:

首先,消除telnetlib作为你的问题:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("remote.host", 23))
If that succeeds, there is a problem in your usage of telnetlib, and we'll need to see an example. If it fails, then you have a basic networking problem, and Lance's suggestion of pulling out ethereal/wireshark is your next step.

#1


It would be a good idea to trace both connection attempts (a failing case and a successful case) with wireshark or similar packet trace tool to see what the difference is at the protocol level.

使用wireshark或类似的数据包跟踪工具跟踪连接尝试(失败案例和成功案例)是一个好主意,以查看协议级别的差异。

#2


First, eliminate telnetlib as your problem:

首先,消除telnetlib作为你的问题:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("remote.host", 23))
If that succeeds, there is a problem in your usage of telnetlib, and we'll need to see an example. If it fails, then you have a basic networking problem, and Lance's suggestion of pulling out ethereal/wireshark is your next step.