Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a Java application that runs on both Windows and Mac. It communicates with various different servers but needs to behave differently depending whether it is using WiFi or a wired connection.

Is there anyway to work out which it is using?

I've looked at using NetworkInterface.getNetworkInterfaces() but that doesn't tell me which NetworkInterface is being used and whether it is WiFi or not.

share|improve this question

migrated from May 28 '13 at 1:13

This question came from our site for professional and enthusiast programmers.

Is the problem bandwidth? If yes, at launch time you may evaluate it to conclude: >250 MBps ==> network else WiFi – Aubin May 24 '13 at 11:17
The problem is packet loss - the application uses UDP not TCP and I've found that the packet loss is much worse on Wi-Fi. – tjlprice May 24 '13 at 11:23
up vote 0 down vote accepted

The only way to do this using native APIs.

These can be interfaced to from Java using JNA. On Mac, you'll need to use something like on top of JNA to use the Objective-C framework.

share|improve this answer

With java.lang.ProcessBuilder you may execute ipconfig /all under Windows and /sbin/ifconfig -a under Linux (and Mac?) to answer the question "How am I connected to the network?".

To be more complete and accurate, you may enforce your protocol to add auto adaptive behavior: the quality, the bandwidth, the number of loss packets, and so on, allow you to decide how to drive your protocol.

You may use TCP/IP to drive the logic of the exchange (behavior, control) and use UDP for the data. First layer: UDP assumes discovery and data, second layer built on TCP to offer sessions management.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .