【问题标题】:Http through telnet with python and twisted使用python和twisted通过telnet进行http
【发布时间】:2011-11-13 08:50:14
【问题描述】:

这就是我想做的:

web-browser --> 通过 telnet(server1) 连接到远程服务器 --> 通过端口 80(server2) 上的 telnet 连接到 squid-proxy(需要身份验证)

我编写了一个使用 Twisted 的小型 Python 脚本(这里:

#! /usr/bin/python
from twisted.internet import reactor, protocol
from twisted.web import http
from telnetlib import Telnet
import getpass
from sys import stdout

class datareceiver(protocol.Protocol):
    def dataReceived(self,data):
        self.telnet_con.write(data)
        stdout.write( self.telnet_con.read_all() )

    def connectionMade(data):
        stdout.write("\nA connection was made to this server\n")

def main():
    server1 = "10.1.1.1"
    #user = raw_input("Enter your remote account: ")
    password = getpass.getpass()
    tn = Telnet(server1)

    if password:
        tn.read_until("Password: ")
        tn.write(password + "\n")

    #This is server2
    tn.write("telnet 10.1.1.10 80 \n")


    #serverfac = protocol.Factory()
    serverfac = http.HTTPFactory()
    datareceiver.telnet_con = tn
    serverfac.protocol = datareceiver
    reactor.listenTCP(9229,serverfac)

    reactor.run()
    tn.write("exit\n")

    print tn.read_all()

if __name__ == "__main__":
    main()

但后来我意识到我做错了,我的 shell 正在从 squid 而不是浏览器获取所有回复。 有人可以概述这样做的正确方法吗? 我应该用其他东西代替扭曲吗?

【问题讨论】:

  • 用python没必要,其他什么都行
  • 这个问题不是很容易理解。如果您尝试澄清您要完成的工作,这可能会有所帮助。
  • 我必须通过另一台服务器(实际上是一个交换机)访问一个 squid-proxy-server(端口 80 上的服务器)。我可以 telnet 进入交换机,然后从那里使用 telnet 连接到 squid-proxy 服务器。简而言之,我想通过那个交换机来隧道我的 http 连接

标签: python proxy twisted telnet


【解决方案1】:

我想你想看看twisted.web.server.Sitetwisted.web.resource.Resource。此外,由于您使用的是 Twisted,因此您可能希望使用twisted.protocols.telnet.Telnet 进行远程登录连接,否则您的应用程序将不会是异步的。

This blog postthis answer here 也可能有用。

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2017-01-08
    • 1970-01-01
    • 2019-01-01
    • 2011-11-15
    • 2015-10-01
    • 2010-12-26
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    相关资源
    最近更新 更多