Some updates to ip scanner
This commit is contained in:
parent
e7b3c4ba5a
commit
b30fcba967
3 changed files with 19 additions and 22 deletions
22
src/se/hal/plugin/netscan/NetworkDevice.java → src/se/hal/plugin/netscan/LocalNetworkDevice.java
Normal file → Executable file
22
src/se/hal/plugin/netscan/NetworkDevice.java → src/se/hal/plugin/netscan/LocalNetworkDevice.java
Normal file → Executable file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
|
||||
private ScheduledExecutorService executor;
|
||||
private HalEventReportListener listener;
|
||||
private ArrayList<NetworkDevice> devices = new ArrayList<>();
|
||||
private ArrayList<LocalNetworkDevice> 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) {
|
||||
|
|
|
|||
2
src/se/hal/plugin/netscan/plugin.json
Normal file → Executable file
2
src/se/hal/plugin/netscan/plugin.json
Normal file → Executable file
|
|
@ -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"}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue