blob: f1fe830f49509bcdc2e6fdbc3cadb9db6c52d4c8 [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
15#
16# get know where to connect
17#
18host = input("hostname: ")
19try:
20 port = int(input("port : "))
21except:
22 port = 0;
23user = input("username: ")
24
25#
26# set SSH settings
27#
28if user:
29 ssh = nc.SSH(username=user)
30else:
31 ssh = nc.SSH()
32ssh.setAuthInteractiveClb(interactive_auth)
33ssh.setAuthPasswordClb(password_auth)
34
35#
36# create NETCONF session to the server
37#
38try:
39 session = nc.Session(host, port, ssh)
40except Exception as e:
41 print(e)
42 sys.exit(1)
43
44#
45# print the list of the NETCONF server capabilities
46#
47print("\nNETCONF server capabilities from " + (host if host else "localhost") + ":" + (port if port else "830") + ":")
48for c in session.capabilities:
49 print(c)
50