From b30fcba967410abd7ac661c10d0c6ac135a53add Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 3 Oct 2016 17:48:00 +0200 Subject: [PATCH] Some updates to ip scanner --- ...orkDevice.java => LocalNetworkDevice.java} | 22 +++++++++---------- .../hal/plugin/netscan/NetScanController.java | 17 +++++++------- src/se/hal/plugin/netscan/plugin.json | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) rename src/se/hal/plugin/netscan/{NetworkDevice.java => LocalNetworkDevice.java} (63%) mode change 100644 => 100755 mode change 100644 => 100755 src/se/hal/plugin/netscan/plugin.json diff --git a/src/se/hal/plugin/netscan/NetworkDevice.java b/src/se/hal/plugin/netscan/LocalNetworkDevice.java old mode 100644 new mode 100755 similarity index 63% rename from src/se/hal/plugin/netscan/NetworkDevice.java rename to src/se/hal/plugin/netscan/LocalNetworkDevice.java index d3dd2abf..26bb746b --- a/src/se/hal/plugin/netscan/NetworkDevice.java +++ b/src/se/hal/plugin/netscan/LocalNetworkDevice.java @@ -6,36 +6,34 @@ import se.hal.intf.HalEventData; import se.hal.struct.devicedata.SwitchEventData; import zutil.ui.Configurator; -import java.net.InetAddress; - /** * Created by Ziver on 2016-10-02. */ -public class NetworkDevice implements HalEventConfig { +public class LocalNetworkDevice implements HalEventConfig { @Configurator.Configurable("IP Address") - private String ip; + private String host; - public NetworkDevice() { } - public NetworkDevice(String hostAddress) { - this.ip = hostAddress; + public LocalNetworkDevice() { } + public LocalNetworkDevice(String hostAddress) { + this.host = hostAddress; } - public String getIp() { - return ip; + public String getHost() { + return host; } @Override public String toString(){ - return "IP: "+ip; + return "Host: "+ host; } @Override public boolean equals(Object obj){ - if (obj instanceof NetworkDevice) - return ip != null && ip.equals(((NetworkDevice) obj).ip); + if (obj instanceof LocalNetworkDevice) + return host != null && host.equals(((LocalNetworkDevice) obj).host); return false; } diff --git a/src/se/hal/plugin/netscan/NetScanController.java b/src/se/hal/plugin/netscan/NetScanController.java index fb6e3726..5ec258d7 100755 --- a/src/se/hal/plugin/netscan/NetScanController.java +++ b/src/se/hal/plugin/netscan/NetScanController.java @@ -25,7 +25,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo private ScheduledExecutorService executor; private HalEventReportListener listener; - private ArrayList devices = new ArrayList<>(); + private ArrayList devices = new ArrayList<>(); @@ -56,13 +56,12 @@ public class NetScanController implements HalEventController, HalAutoScannableCo @Override public void run() { - try{ - MultiCommandExecutor executor = new MultiCommandExecutor(); + try(MultiCommandExecutor executor = new MultiCommandExecutor();){ for (int i = 0; i < devices.size(); i++) { - NetworkDevice device = devices.get(i); + LocalNetworkDevice device = devices.get(i); if (listener != null) { - logger.fine("Pinging ip: "+device.getIp()); - boolean online = InetScanner.isReachable(InetAddress.getByName(device.getIp()), executor); + logger.fine("Pinging ip: "+device.getHost()); + boolean online = InetScanner.isReachable(device.getHost(), executor); listener.reportReceived(device, new SwitchEventData(online, System.currentTimeMillis())); } } @@ -75,7 +74,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo logger.fine("Detected ip: "+ip.getHostAddress()); if (listener != null) listener.reportReceived( - new NetworkDevice(ip.getHostAddress()), + new LocalNetworkDevice(ip.getHostAddress()), new SwitchEventData(true, System.currentTimeMillis())); } @@ -83,8 +82,8 @@ public class NetScanController implements HalEventController, HalAutoScannableCo @Override public void register(HalEventConfig event) { - if (event instanceof NetworkDevice) - devices.add((NetworkDevice) event); + if (event instanceof LocalNetworkDevice) + devices.add((LocalNetworkDevice) event); } @Override public void deregister(HalEventConfig event) { diff --git a/src/se/hal/plugin/netscan/plugin.json b/src/se/hal/plugin/netscan/plugin.json old mode 100644 new mode 100755 index 67e3db04..a1cc2858 --- a/src/se/hal/plugin/netscan/plugin.json +++ b/src/se/hal/plugin/netscan/plugin.json @@ -3,6 +3,6 @@ "name": "Network Scanner", "interfaces": [ {"se.hal.intf.HalAutoScannableController": "se.hal.plugin.netscan.NetScanController"}, - {"se.hal.intf.HalEventConfig": "se.hal.plugin.netscan.NetworkDevice"} + {"se.hal.intf.HalEventConfig": "se.hal.plugin.netscan.LocalNetworkDevice"} ] } \ No newline at end of file