这是以下问题的扩展: NetworkInterface.getNetworkInterfaces() not listing all interfaces
我在嵌入式设备中有4个接口,如果我运行ifconfig,我会得到以下输出
eth0 Link encap:Ethernet HWaddr 04:a3:16:b0:a9:d7
inet addr:192.168.60.112 Bcast:192.168.60.255 Mask:255.255.255.0
inet6 addr: fe80::6a3:16ff:feb0:a9d7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST DYNAMIC MTU:1500 Metric:1
RX packets:73134 errors:0 dropped:202 overruns:0 frame:0
TX packets:17867 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14662058 (13.9 MiB) TX bytes:3698311 (3.5 MiB)
Interrupt:77
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3901 errors:0 dropped:0 overruns:0 frame:0
TX packets:3901 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:266106 (259.8 KiB) TX bytes:266106 (259.8 KiB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet6 addr: fe80::7455:ff:fe00:0/0 Scope:Link
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:667 errors:0 dropped:0 overruns:0 frame:0
TX packets:712 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:87072 (85.0 KiB) TX bytes:70380 (68.7 KiB)
wlan0 Link encap:Ethernet HWaddr 7c:dd:90:90:99:97
UP BROADCAST MULTICAST DYNAMIC MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
我从https://docs.oracle.com/javase/tutorial/networking/nifs/listing.html获取了一个示例Java代码来列出所有网络接口,如果我从控制台运行它,我会得到以下输出。
Display name: tun0
Name: tun0
InetAddress: /fe80:0:0:0:7455:ff:fe00:0%3
Display name: eth0
Name: eth0
InetAddress: /fe80:0:0:0:6a3:16ff:feb0:a9d7%2
InetAddress: /192.168.60.112
Display name: lo
Name: lo
InetAddress: /0:0:0:0:0:0:0:1%1
InetAddress: /127.0.0.1
如果我使用 exec 节点从同一嵌入式设备中安装的Node-red运行相同的java类,我将获得以下输出
Display name: eth0
Name: eth0
InetAddress: /192.168.60.112
Display name: lo
Name: lo
InetAddress: /127.0.0.1
我已经理解了缺少wlan0接口的原因,这是因为接口没有配置。但我不明白为什么我无法在Node-red / NodeJS中看到tun0接口,而如果我从命令行运行相同的类,我就能看到该接口。我能够从Node-red ping tun0接口,这意味着只有Java运行NodeJS才会出现问题。
我在调试从Node-red运行的java应用程序时发现了这个问题。我能够从控制台运行该应用程序没有任何问题但是当我从Node-red运行它时出现以下错误。
java.net.UnknownHostException: no such interface tun0
有人可以帮我这个吗?