import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
+import java.time.Duration;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
return null;
}
- String cmd = String.format(COMMAND, hostName);
- String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
+ String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
+ String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
Matcher matcher = MAC_REGEX.matcher(response);
String macAddress = null;
if (macAddress != null) {
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
} else {
- LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}", cmd, hostName, response);
+ LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}",
+ String.format(COMMAND, hostName), hostName, response);
}
return macAddress;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.*;
-import java.util.*;
+import java.net.ConnectException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.NoRouteToHostException;
+import java.net.PortUnreachableException;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.time.Duration;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
* Return true if the external arp ping utility (arping) is available and executable on the given path.
*/
public ArpPingUtilEnum determineNativeARPpingMethod(String arpToolPath) {
- String result = ExecUtil.executeCommandLineAndWaitResponse(arpToolPath + " --help", 100);
+ String result = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(100), arpToolPath, "--help");
if (StringUtils.isBlank(result)) {
return ArpPingUtilEnum.UNKNOWN_TOOL;
} else if (result.contains("Thomas Habets")) {
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
+import java.time.Duration;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
return null;
}
- String cmd = String.format(COMMAND, hostName);
- String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
+ String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
+ String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
Matcher matcher = MAC_REGEX.matcher(response);
String macAddress = null;
if (macAddress != null) {
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
} else {
- LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}", cmd, hostName, response);
+ LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}",
+ String.format(COMMAND, hostName), hostName, response);
}
return macAddress;
}
*/
package org.openhab.transform.exec.internal;
+import java.time.Duration;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.net.exec.ExecUtil;
long startTime = System.currentTimeMillis();
String formattedCommandLine = String.format(commandLine, source);
- String result = ExecUtil.executeCommandLineAndWaitResponse(formattedCommandLine, 5000);
+ String result = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofSeconds(5),
+ formattedCommandLine.split(" "));
logger.trace("command line execution elapsed {} ms", System.currentTimeMillis() - startTime);
return result;