1313package org .openhab .core .config .core .internal .net ;
1414
1515import java .net .Inet4Address ;
16- import java .net .InetAddress ;
1716import java .net .NetworkInterface ;
1817import java .net .SocketException ;
1918import java .net .URI ;
2221import java .util .Enumeration ;
2322import java .util .List ;
2423import java .util .Locale ;
24+ import java .util .Objects ;
2525import java .util .stream .Stream ;
2626
2727import org .eclipse .jdt .annotation .NonNullByDefault ;
3030import org .openhab .core .config .core .ParameterOption ;
3131import org .openhab .core .net .CidrAddress ;
3232import org .openhab .core .net .NetUtil ;
33+ import org .openhab .core .util .StringUtils ;
3334import org .osgi .service .component .annotations .Component ;
3435
3536/**
@@ -67,8 +68,10 @@ public class NetworkConfigOptionProvider implements ConfigOptionProvider {
6768 Enumeration <NetworkInterface > networkInterfaces = NetworkInterface .getNetworkInterfaces ();
6869 while (networkInterfaces .hasMoreElements ()) {
6970 NetworkInterface networkInterface = networkInterfaces .nextElement ();
70- options .add (new ParameterOption (networkInterface .getName (),
71- getNetworkInterfaceLabel (networkInterface )));
71+ if (networkInterface .isUp ()) {
72+ options .add (new ParameterOption (networkInterface .getName (),
73+ getNetworkInterfaceLabel (networkInterface )));
74+ }
7275 }
7376 return options ;
7477 } catch (SocketException e ) {
@@ -80,18 +83,6 @@ public class NetworkConfigOptionProvider implements ConfigOptionProvider {
8083 }
8184
8285 private String getNetworkInterfaceLabel (NetworkInterface networkInterface ) {
83- Enumeration <InetAddress > inetAddresses = networkInterface .getInetAddresses ();
84- String hostName = null ;
85- while (inetAddresses .hasMoreElements ()) {
86- InetAddress inetAddress = inetAddresses .nextElement ();
87- if (inetAddress instanceof Inet4Address ) {
88- hostName = inetAddress .getHostName ();
89- break ;
90- } else if (hostName == null ) {
91- hostName = inetAddress .getHostName ();
92- }
93- }
94- return hostName == null ? networkInterface .getName ()
95- : String .format ("%s (%s)" , networkInterface .getName (), hostName );
86+ return Objects .requireNonNull (StringUtils .capitalizeByWhitespace (networkInterface .getName ().replace ('_' , ' ' )));
9687 }
9788}
0 commit comments