Guest User

Untitled

a guest
Dec 17th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package org.tom;
  2.  
  3. import com.tailf.jnc.*;
  4.  
  5. import java.io.IOException;
  6.  
  7. public class Main {
  8. static void dumpNode(Element e, String pad) {
  9. Element n = e.getChild("name");
  10. if (n != null) {
  11. System.out.println(pad + n.value);
  12. Element s = e.getChild("section");
  13. if (s != null) {
  14. for (Element el2 : s.getChildren()) {
  15. dumpNode(el2, pad+ "--");
  16. }
  17. } else {
  18. Element v = e.getChild("value");
  19. if (v != null) {
  20. System.out.println(pad + "*" + v.value);
  21. }
  22. }
  23. }
  24.  
  25. }
  26.  
  27. public static void main(String[] args) {
  28. DeviceUser user = new DeviceUser("nc", "nc", "baracuda");
  29. Device device = new Device("t", user, "192.168.1.3", 22);
  30.  
  31. try {
  32. device.connect("nc");
  33. device.newSession("abc");
  34.  
  35. NodeSet ns = device.getSession("abc").getConfig(NetconfSession.RUNNING);
  36. for (Element el : ns) {
  37. for (Element el2 : el.getChildren()) {
  38. dumpNode(el2, "");
  39. }
  40.  
  41. }
  42. System.out.println(ns);
  43. } catch (IOException e) {
  44. e.printStackTrace();
  45. } catch (JNCException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment