Created
December 15, 2017 09:16
-
-
Save tom-code/6f93e16f479bb8d23c79a6ca02d8b779 to your computer and use it in GitHub Desktop.
netconf client java miniexample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.tom; | |
import com.tailf.jnc.*; | |
import java.io.IOException; | |
public class Main { | |
static void dumpNode(Element e, String pad) { | |
Element n = e.getChild("name"); | |
if (n != null) { | |
System.out.println(pad + n.value); | |
Element s = e.getChild("section"); | |
if (s != null) { | |
for (Element el2 : s.getChildren()) { | |
dumpNode(el2, pad+ "--"); | |
} | |
} else { | |
Element v = e.getChild("value"); | |
if (v != null) { | |
System.out.println(pad + "*" + v.value); | |
} | |
} | |
} | |
} | |
public static void main(String[] args) { | |
DeviceUser user = new DeviceUser("nc", "nc", "baracuda"); | |
Device device = new Device("t", user, "192.168.1.3", 22); | |
try { | |
device.connect("nc"); | |
device.newSession("abc"); | |
NodeSet ns = device.getSession("abc").getConfig(NetconfSession.RUNNING); | |
for (Element el : ns) { | |
for (Element el2 : el.getChildren()) { | |
dumpNode(el2, ""); | |
} | |
} | |
System.out.println(ns); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (JNCException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment