File tree 2 files changed +28
-4
lines changed
cc/arduino/packages/discoverers
2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,7 @@ public List<BoardPort> discovery() {
75
75
ports .add (0 , 22 );
76
76
}
77
77
78
- boolean reachable = false ;
79
- for (Integer port : ports ) {
80
- reachable = reachable || NetUtils .isReachable (inetAddress , port );
81
- }
78
+ boolean reachable = NetUtils .isReachable (inetAddress , ports );
82
79
if (!reachable ) {
83
80
boardPortIterator .remove ();
84
81
}
Original file line number Diff line number Diff line change 4
4
import java .net .InetAddress ;
5
5
import java .net .InetSocketAddress ;
6
6
import java .net .Socket ;
7
+ import java .util .Arrays ;
8
+ import java .util .List ;
7
9
8
10
public abstract class NetUtils {
9
11
12
+ private static boolean isReachableByEcho (InetAddress address ) {
13
+ try {
14
+ return address .isReachable (100 );
15
+ } catch (IOException e ) {
16
+ return false ;
17
+ }
18
+ }
19
+
10
20
public static boolean isReachable (InetAddress address , int port ) {
21
+ return isReachable (address , Arrays .asList (port ));
22
+ }
23
+
24
+ public static boolean isReachable (InetAddress address , List <Integer > ports ) {
25
+ if (isReachableByEcho (address )) {
26
+ return true ;
27
+ }
28
+
29
+ boolean reachable = false ;
30
+ for (Integer port : ports ) {
31
+ reachable = reachable || isPortOpen (address , port );
32
+ }
33
+
34
+ return reachable ;
35
+ }
36
+
37
+ private static boolean isPortOpen (InetAddress address , int port ) {
11
38
Socket socket = null ;
12
39
try {
13
40
socket = new Socket ();
You can’t perform that action at this time.
0 commit comments