blob: 7a96139bc54199d02586ec599d458a7b333b7c66 [file] [log] [blame]
Radek Krejcib73b7612017-06-21 13:48:40 +02001#!/usr/bin/python3
2
3import sys
4import os
5import getpass
6import netconf2 as nc
7
8def interactive_auth(name, instruct, prompt, data):
9 print(name)
10 return getpass.getpass(prompt)
11
12def password_auth(user, host, data):
13 return getpass.getpass((user if user else os.getlogin()) + '@' + host + ' password : ')
14
Radek Krejci45f6e8f2018-02-13 16:56:53 +010015def hostkey_check(hostname, state, keytype, hexa, priv):
16 return True
17
Radek Krejcib73b7612017-06-21 13:48:40 +020018#
19# get know where to connect
20#
21host = input("hostname: ")
22try:
23 port = int(input("port : "))
24except:
25 port = 0;
26user = input("username: ")
27
28#
29# set SSH settings
30#
31if user:
32 ssh = nc.SSH(username=user)
33else:
34 ssh = nc.SSH()
35ssh.setAuthInteractiveClb(interactive_auth)
36ssh.setAuthPasswordClb(password_auth)
Radek Krejci45f6e8f2018-02-13 16:56:53 +010037ssh.setAuthHostkeyCheckClb(hostkey_check)
Radek Krejcib73b7612017-06-21 13:48:40 +020038
39#
40# create NETCONF session to the server
41#
42try:
43 session = nc.Session(host, port, ssh)
44except Exception as e:
45 print(e)
46 sys.exit(1)
47
48#
49# print the list of the NETCONF server capabilities
50#
Radek Krejcia3e1bc72017-09-21 13:00:03 +020051print("\nNETCONF server capabilities from " + (host if host else "localhost") + ":" + (str(port) if port else "830") + " (session ID " + str(session.id) + "):")
Radek Krejcib73b7612017-06-21 13:48:40 +020052for c in session.capabilities:
53 print(c)
54