Added example
This commit is contained in:
parent
8776d15405
commit
dddab100f9
|
|
@ -0,0 +1,15 @@
|
|||
package examples;
|
||||
|
||||
/**
|
||||
* Config class for examples
|
||||
* @author gideon
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
|
||||
public static final String USERNAME = "admin";
|
||||
public static final String PASSWORD = "";
|
||||
public static final String HOST = "10.0.1.3";
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package examples;
|
||||
|
||||
import me.legrange.mikrotik.ApiConnection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author gideon
|
||||
*/
|
||||
abstract class Example {
|
||||
|
||||
protected void connect() throws Exception {
|
||||
con = ApiConnection.connect(Config.HOST);
|
||||
con.login(Config.USERNAME, Config.PASSWORD);
|
||||
}
|
||||
|
||||
protected void disconnect() throws Exception {
|
||||
con.disconnect();
|
||||
}
|
||||
|
||||
protected ApiConnection con;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package examples;
|
||||
|
||||
import me.legrange.mikrotik.MikrotikApiException;
|
||||
|
||||
/**
|
||||
* Example 1: A very simple example: Reboot the remote router
|
||||
* @author gideon
|
||||
*/
|
||||
public class Example1 extends Example {
|
||||
|
||||
public static void main(String...args) throws Exception {
|
||||
Example1 ex = new Example1();
|
||||
ex.connect();
|
||||
ex.test();
|
||||
ex.disconnect();
|
||||
}
|
||||
|
||||
private void test() throws MikrotikApiException {
|
||||
con.execute("/system/reboot");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package examples;
|
||||
|
||||
import java.util.List;
|
||||
import me.legrange.mikrotik.MikrotikApiException;
|
||||
import me.legrange.mikrotik.Result;
|
||||
|
||||
/**
|
||||
* Example 2: Print all interfaces
|
||||
*
|
||||
* @author gideon
|
||||
*/
|
||||
public class Example2 extends Example {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
Example2 ex = new Example2();
|
||||
ex.connect();
|
||||
ex.test();
|
||||
ex.disconnect();
|
||||
}
|
||||
|
||||
private void test() throws MikrotikApiException {
|
||||
List<Result> results = con.execute("/interface/print");
|
||||
for (Result result : results) {
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package examples;
|
||||
|
||||
import java.util.List;
|
||||
import me.legrange.mikrotik.MikrotikApiException;
|
||||
import me.legrange.mikrotik.Result;
|
||||
|
||||
/**
|
||||
* Example 2: Print all interfaces
|
||||
*
|
||||
* @author gideon
|
||||
*/
|
||||
public class Example2 extends Example {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
Example2 ex = new Example2();
|
||||
ex.connect();
|
||||
ex.test();
|
||||
ex.disconnect();
|
||||
}
|
||||
|
||||
private void test() throws MikrotikApiException {
|
||||
List<Result> results = con.execute("/interface/print");
|
||||
for (Result result : results) {
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package examples;
|
|||
import me.legrange.mikrotik.MikrotikApiException;
|
||||
|
||||
/**
|
||||
* Example 1: A very simple example: Reboot the remote router
|
||||
* Example 1: A very simple command: Reboot the remote router
|
||||
* @author gideon
|
||||
*/
|
||||
public class Example1 extends Example {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import me.legrange.mikrotik.MikrotikApiException;
|
|||
import me.legrange.mikrotik.Result;
|
||||
|
||||
/**
|
||||
* Example 2: Print all interfaces
|
||||
* Example 2: A command that returns results. Print all interfaces
|
||||
*
|
||||
* @author gideon
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package examples;
|
||||
|
||||
import java.util.List;
|
||||
import me.legrange.mikrotik.MikrotikApiException;
|
||||
import me.legrange.mikrotik.Result;
|
||||
|
||||
/**
|
||||
* Example 3: Queries. Print all interfaces of a certain type.
|
||||
*
|
||||
* @author gideon
|
||||
*/
|
||||
public class Example3 extends Example {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
Example3 ex = new Example3();
|
||||
ex.connect();
|
||||
ex.test();
|
||||
ex.disconnect();
|
||||
}
|
||||
|
||||
private void test() throws MikrotikApiException {
|
||||
List<Result> results = con.execute("/interface/print where type=ether");
|
||||
for (Result result : results) {
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue