Added trim() to cope with spaces around host nameS

This commit is contained in:
GideonLeGrange 2014-12-22 12:55:59 +02:00
parent 3f6a930a4d
commit 047cd4246b
2 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,28 @@
package examples;
import java.util.List;
import java.util.Map;
import me.legrange.mikrotik.MikrotikApiException;
/**
* Example 7: Dump your complete config
*
* @author gideon
*/
public class Example8 extends Example {
public static void main(String... args) throws Exception {
Example8 ex = new Example8();
ex.connect();
ex.test();
ex.disconnect();
}
private void test() throws MikrotikApiException, InterruptedException {
List<Map<String, String>> res = con.execute("/ip/hotspot/user/print where uptime!=1");
for (Map<String, String> r : res) {
System.out.println(r);
}
// con.execute("/ip/firewall/filter/add chain=forward hotspot=!auth protocol=tcp src-port=8000-8084");
}
}

View File

@ -164,7 +164,7 @@ public final class ApiConnectionImpl extends ApiConnection {
*/ */
private void open(String host, int port, boolean secure) throws ApiConnectionException { private void open(String host, int port, boolean secure) throws ApiConnectionException {
try { try {
InetAddress ia = InetAddress.getByName(host); InetAddress ia = InetAddress.getByName(host.trim());
if (secure) { if (secure) {
sock = openSSLSocket(ia, port); sock = openSSLSocket(ia, port);
} else { } else {