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 | |
Radek Krejci | 45f6e8f | 2018-02-13 16:56:53 +0100 | [diff] [blame^] | 15 | def hostkey_check(hostname, state, keytype, hexa, priv): |
| 16 | return True |
| 17 | |
Radek Krejci | b73b761 | 2017-06-21 13:48:40 +0200 | [diff] [blame] | 18 | # |
| 19 | # get know where to connect |
| 20 | # |
| 21 | host = input("hostname: ") |
| 22 | try: |
| 23 | port = int(input("port : ")) |
| 24 | except: |
| 25 | port = 0; |
| 26 | user = input("username: ") |
| 27 | |
| 28 | # |
| 29 | # set SSH settings |
| 30 | # |
| 31 | if user: |
| 32 | ssh = nc.SSH(username=user) |
| 33 | else: |
| 34 | ssh = nc.SSH() |
| 35 | ssh.setAuthInteractiveClb(interactive_auth) |
| 36 | ssh.setAuthPasswordClb(password_auth) |
Radek Krejci | 45f6e8f | 2018-02-13 16:56:53 +0100 | [diff] [blame^] | 37 | ssh.setAuthHostkeyCheckClb(hostkey_check) |
Radek Krejci | b73b761 | 2017-06-21 13:48:40 +0200 | [diff] [blame] | 38 | |
| 39 | # |
| 40 | # create NETCONF session to the server |
| 41 | # |
| 42 | try: |
| 43 | session = nc.Session(host, port, ssh) |
| 44 | except Exception as e: |
| 45 | print(e) |
| 46 | sys.exit(1) |
| 47 | |
| 48 | # |
| 49 | # print the list of the NETCONF server capabilities |
| 50 | # |
Radek Krejci | a3e1bc7 | 2017-09-21 13:00:03 +0200 | [diff] [blame] | 51 | print("\nNETCONF server capabilities from " + (host if host else "localhost") + ":" + (str(port) if port else "830") + " (session ID " + str(session.id) + "):") |
Radek Krejci | b73b761 | 2017-06-21 13:48:40 +0200 | [diff] [blame] | 52 | for c in session.capabilities: |
| 53 | print(c) |
| 54 | |