Radek Krejci | b73b761 | 2017-06-21 13:48:40 +0200 | [diff] [blame^] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import getpass |
| 6 | import netconf2 as nc |
| 7 | |
| 8 | def interactive_auth(name, instruct, prompt, data): |
| 9 | print(name) |
| 10 | return getpass.getpass(prompt) |
| 11 | |
| 12 | def 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 | # |
| 18 | host = input("hostname: ") |
| 19 | try: |
| 20 | port = int(input("port : ")) |
| 21 | except: |
| 22 | port = 0; |
| 23 | user = input("username: ") |
| 24 | |
| 25 | # |
| 26 | # set SSH settings |
| 27 | # |
| 28 | if user: |
| 29 | ssh = nc.SSH(username=user) |
| 30 | else: |
| 31 | ssh = nc.SSH() |
| 32 | ssh.setAuthInteractiveClb(interactive_auth) |
| 33 | ssh.setAuthPasswordClb(password_auth) |
| 34 | |
| 35 | # |
| 36 | # create NETCONF session to the server |
| 37 | # |
| 38 | try: |
| 39 | session = nc.Session(host, port, ssh) |
| 40 | except Exception as e: |
| 41 | print(e) |
| 42 | sys.exit(1) |
| 43 | |
| 44 | # |
| 45 | # print the list of the NETCONF server capabilities |
| 46 | # |
| 47 | print("\nNETCONF server capabilities from " + (host if host else "localhost") + ":" + (port if port else "830") + ":") |
| 48 | for c in session.capabilities: |
| 49 | print(c) |
| 50 | |