目前使用libmproxy,又使用telnetlib,发出请求到HTTPS网页.但是,会引发以下错误:
Error: [('SSL routines', 'SSL3_READ_BYTES', 'tlsv1 alert unknown ca')]
Run Code Online (Sandbox Code Playgroud)
我认为这与无法验证担保页面使用的证书的CA的身份有关.我认为应该有一个可以打开(或关闭)的设置,可以绕过验证 - 我对验证数字签名者的身份不感兴趣.
我认为一种可能的,丑陋的解决方案可能是修补代码以捕获异常并忽略它,但我宁愿采用更清晰,更受支持的方式来实现它.
什么是避免/解决这个问题的好方法?
非常感谢!
所以我正在尝试python docs给出的这个非常简单的例子:
import getpass
import sys
import telnetlib
HOST = "<HOST_IP>"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
Run Code Online (Sandbox Code Playgroud)
我的问题是它挂在read_all()的末尾...它不打印任何东西.我之前从未使用过这个模块,所以我试图让这个真正基本的例子继续下去.顺便说一下,我正在使用python 2.4谢谢.
我正在尝试使用telnetlib在Telnet会话中捕获和操作数据,事情进展顺利,但是我对Python的新见解让我头疼.
My issue is pretty straight forward, I am able to capture and display the data I want (So far) however I just seem to be cycling through errors whenever I try to remove the last line of data from the data I have captured. My code goes something like this:
... Snipped Boring Stuff ...
tn.write('command to gather data' + '\r')
data = tn.read_very_eager()
print data
... snipped more boring stuff ...
Run Code Online (Sandbox Code Playgroud)
Pretty simple... So, how in the world …
我正在使用Python的telnetlib telnet到某台机器并执行一些命令,我想得到这些命令的输出.
那么,目前的情况是什么 -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
tn.write("command2")
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
#here I get the whole output
Run Code Online (Sandbox Code Playgroud)
现在,我可以在sess_op中获得所有合并输出.
但是,我想要的是在执行command1之后立即获取command1的输出,就像我在其他机器的shell中工作一样,如下所示 -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
#here I want to get the output for command1
tn.write("command2")
#here I want to get the output for command2
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print …Run Code Online (Sandbox Code Playgroud) 当通过telnet执行的命令通过控制台继续响应时,是否可以逐行打印telnet响应?
示例:我已经执行了一个命令(收集日志),它继续在控制台窗口上显示日志.我们可以逐行读取响应并打印它,而不会遗漏任何单行吗?
在片段下面写入日志,但仅在特定时间之后.如果我在其间停止服务/脚本(CTRL-C),则不会写任何内容.
import sys
import telnetlib
import time
orig_stdout = sys.stdout
f = open('outpuy.txt', 'w')
sys.stdout = f
try:
tn = telnetlib.Telnet(IP)
tn.read_until(b"pattern1")
tn.write(username.encode('ascii') + b"\n")
tn.read_until(b"pattern2")
tn.write(command1.encode('ascii') + b"\n")
z = tn.read_until(b'abcd\b\n',600)
array = z.splitlines( )
except:
sys.exit("Telnet Failed to ", IP)
for i in array:
i=i.strip()
print(i)
sys.stdout = orig_stdout
f.close()
Run Code Online (Sandbox Code Playgroud) 我正在编写一个库来支持远程服务器和运行应用程序的 telnet。
在建立连接、取回数据、解析等方面进展顺利(至少就像通过文本界面与程序通信一样顺利)。
如果输入正确,一个应用程序将更改光标,如果输入失败,则保留原始光标(我不编写应用程序,我只需要使用它们。)
当所述应用程序正确启动时,这没有问题:
promptB = "hello(x)# " # Yes, the space at the end is intentional
response = tn_conn.cmd("app_name\n", prompt=promptB)
Run Code Online (Sandbox Code Playgroud)
我想使用提示更改(或缺少提示更改)来检测程序是否无法启动。我认为这将是尝试 telnetlib 的 expect() 的绝佳机会,因为 expect() 允许传递字符串列表以匹配响应。
但是,我不能让它发挥作用:
promptA = "hello(x)# " # Yes, the space at the end is intentional
promptB = "hello> " # Yes, the space at the end is intentional
tn_conn.write("app_name\n")
which_prompt, mo, response = self.tn_conn.expect([promptA, promptB], timeout=3)
Run Code Online (Sandbox Code Playgroud)
无论应用程序是否成功启动,expect 命令总是超时。
which = "-1"
莫 = 无
response = "mumble mumble\r\r\n 其他东西\r\n\r\n你好#"
文档说可以将字符串或正则表达式对象传递给期望(我正在传递一个字符串),所以我错过了什么吗?查看 telnetlib 代码表明它调用的是 …
我想检查使用 telnetlib 的连接是否仍然存在。
我这样做的方法是发送ls命令并检查答案,但我确信必须有更流畅的解决方案。
你好,最近我开始使用telnetlib,现在我需要通过代理路由它。我问自己是否有办法做到这一点,因为您也可以使用代理,requests.get(proxies=)例如?
所以我需要访问一个telnet会话.更具体地说是JPL的星历服务.我确切地知道在命令提示符中我需要做什么,但是我在使用该telnetlib软件包时遇到了麻烦.
以下是我需要通过命令提示符执行的步骤:
telnet
o horizons.jpl.nasa.gov 6775
DES=C/2012 X1;
y
E
o
H06
y
2013-Nov-7 9:00
2013-Nov-17 9:00
1d
y
1,4,9,19,20,24
Run Code Online (Sandbox Code Playgroud)
然后在那之后有一个大输出,我需要保存到文本文件,或只是保持为变量.我稍后会用它.
按照这些输入逐步进行,可以获得我需要获取的确切信息
有什么建议?
import telnetlib
tn = telnetlib.Telnet(IP)
tn.read_until("abcd login: ") --> This is only to match a particular pattern
Run Code Online (Sandbox Code Playgroud)
可以包含通用模式tn.read_until()吗?例如:提示可以是"xyz login: " , "abcd login: "等
在正则表达式中,我们使用re.match('(.*)login: ',prompt). 但我不这么认为,这是tn.read_until()因为它期望的参数本身是一个模式。有什么办法可以处理吗?
telnetlib ×10
python ×8
telnet ×3
certificate ×1
libmproxy ×1
python-2.4 ×1
regex ×1
ssl ×1
tcp ×1