0

I need to get the interface I'm using, in Windows I can do: InetAddress.getLocalHost () But in Linux it does not work, unless you add to etc / hosts the IP of my computer.

So, I use NetworkInterface.getNetworkInterfaces () to get the list of my interfaces, but I can not differentiate between whether my interface is an ethernet connection or a wifi connection.

I need to know the type of connection to always get first the ethernet connection, if I had it.

Thanks.

accnono
  • 33
  • 7
  • What do you get with NetworkInterface#getName() ? On Linux should be someting like `eth*`, `wlan*`, ... – PeterMmm Dec 16 '16 at 10:51
  • Yes, I have something similiar, but in another Linux with RH, I dont obtain the same names. So is not a good practise take the names to compare, I think. @PeterMmm – accnono Dec 16 '16 at 12:06
  • redhat 7 (and now Ubuntu 16.x and Mint 18.x and probably others) the device names have changed from teh traditional ethX and wlanX. My old eth0 on my current desktop (mint 18) is now "enp63s0". – ivanivan Dec 16 '16 at 14:07
  • yes, that's my problem, I must work with windows and Linux (Ubuntu and RH) and they dont show the same names for ethernet network @ivanivan – accnono Dec 16 '16 at 15:00
  • I cannot imagine any platform independent way to do this (with Java). Probably with `NetworkInterface#getHardwareAddress()` you may run some extern utility like `iwconfig` to match the MAC with an interface. – PeterMmm Dec 16 '16 at 15:18

0 Answers0