Search code examples
javadesktop-applicationethernet

How can I know the application is link to wifi or ethernet use java?


I want detect network is wifi or ethernet at mac and windows.

NetworkInterface.getNetworkInterfaces()

This code can get the name of the networkinterface,but I don't know the network is wifi or ethernet.Please help me....


Solution

  • You cannot know, you're not supposed to need to know, in application code. At the level Java applications run, there is no difference between networks, all you have is a TCP/IP stack and you can't determine based on that what kind of network you're working on.

    You'd have to write something in native code that interfaces with low level operating system functionality (and don't ask me what or how, it's dependent on operating system obviously) to get that information.