ncclient:连接到NETCONF服务器

时间:2019-06-17 15:40:04

标签: ssh ietf-netconf

我想使用带有2.7.15的python库ncclient 0.6.6连接到NETCONF服务器(netopeer2),并读出正在运行的配置。

我尝试按照手册中的示例在控制台中运行以下代码:

with manager.connect(host="*the IP adress*", port=*the port*, timeout=None, username="*user*", password="*pwd*") as m:
    c = m.get_config(source='running').data_xml
    with open("%s.xml" % host, 'w') as f:
        f.write(c)

正如手册中所写,我尝试使用allow_agent和look_for_keys设置为False来禁用公钥身份验证。不幸的是,这不能正常工作,因为我收到了错误消息:

  File "<stdin>", line 1, in <module>
  File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/manager.py", line 177, in connect
    return connect_ssh(*args, **kwds)
  File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/manager.py", line 143, in connect_ssh
    session.connect(*args, **kwds)
  File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/transport/ssh.py", line 481, in connect
    raise SSHUnknownHostError(known_hosts_lookup, fingerprint)
ncclient.transport.errors.SSHUnknownHostError: Unknown host key [e3:8d:35:a9:43:f9:3c:8a:f4:d3:88:5b:a9:36:93:59] for [[192.168.56.2]:1831]

我不明白为什么它仍然抱怨未知的主机密钥,即使我明确禁用了公共密钥身份验证也是如此。 netopeer NETCONF服务器肯定正在运行,因为当我尝试从终端通过SSH进入它时,我会收到“ Hello”消息。 我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

m = manager.connect(host="172.17.0.2", port=830, username="netconf", password="netconf", hostkey_verify=False)

成功了。 Hostkey_verify必须为false。