user89862
user89862

Reputation:

Detect a new network connection (linux-server) and it's status in java

Is there any way that java can detect that I have just plugged in a wired-network, and monitor it's bandwith? (I'm using linux, if that matters)

Upvotes: 2

Views: 2381

Answers (2)

MarkR
MarkR

Reputation: 63538

You can run the program

/sbin/ip monitor

And monitor its output using a pipe or whatever.

It will tell you when

  • New network interfaces are configured
  • Network interfaces go up and down because the network becomes ready / not ready (this typically works by detecting an ethernet carrier or wifi access point)

The output is somewhat confusing but should be parseable.

Upvotes: 0

dfa
dfa

Reputation: 116304

For the sake of simplicity and without using native code, you could try to using java.net.NetworkInterface with polling, so every X seconds you trigger a network interface enumeration in order to see if there are new interfaces.

Upvotes: 1

Related Questions