相关文章推荐
俊秀的大葱  ·  spring boot 3.0.6 ...·  3 月前    · 
想出国的钱包  ·  aapt.exe已停止工作 ...·  4 月前    · 
玩足球的馒头  ·  typeScript ...·  1 年前    · 
没读研的火柴  ·  javascript - ...·  1 年前    · 
client1 = paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client1.connect(IP, username=username, password=password)
configure = client1.invoke_shell()
configure.send('configure')
configure.send('set interfaces ge-0/0/10 description "test"')
configure.send('show | compare')
print configure.recv(1000)
client1.close()
[edit interfaces ge-0/0/10]
-   description "Internet Simulation Interface connect to QFX ge-0/0/21";
+   description test;
但实际的输出是这样的。

JUNOS 12.3X50-D35 built 2013-10-22 07:02:18 UTC

2 个评论
对于上述查询,答案是从paramiko_expect导入 "SSHClientInteraction"。但现在的问题是能够进入配置模式,但无法进一步发送命令
This is the new code ********************* client1 = paramiko.SSHClient() client1.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client1.connect(IP, username=username, password=password) interact = SSHClientInteraction(client1, timeout=10, display=True) #interact.expect ('sivabalask@in.ibm.com@usrdrsf072ccpf0>') interact.send('configure') interact.expect ( interact.send('show | compare') cmd_output = interact.current_output_clean print cmd_output client1.close() ************** There is something else missing.
python
paramiko
juniper
sivabala senna
sivabala senna
发布于 2017-12-08
4 个回答
rllavona13
rllavona13
发布于 2020-12-14
0 人赞同

你得到的是Juniper CLI的第一行,尝试在.NET中编码一个更高的接收字节。

print configure.recv(1000)
print configure.recv(4096)

Let me know.

好吧,我试了一下最大接收数65535,还是没有成功。
rllavona13
rllavona13
发布于 2020-12-14
0 人赞同

我建议你使用Junos Eznc,即juniper为junos设备提供的库。Junos-Eznc GitHub

要使用Junos pyez,需要在所有Juniper设备中启用netconf。
sri
sri
发布于 2020-12-14
0 人赞同

你可以试试下面提到的片段吗?有时,你需要等待几秒钟才能在你的stdin上收到一些字节。

configure.send('show | compare')
time.sleep(2)
print configure.recv(1000)
    
sourjp
sourjp
发布于 2020-12-14
0 人赞同

你能在发送命令之前把'cli'放进去吗?

configure = client1.invoke_shell ()
configure.send ('cli') <--- Add
configure.send ('configure')

当您通过SSH连接到JUNOS时,您首先处于shell模式,所以您可以通过cli移动到操作模式。

(lab-network) bash-3.2$ ssh root@localhost -p 2201 
Password:
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
root@vsrx1% cli
root@vsrx1> configure