Retrieving local networks from Vaadin Flow with Java

Hello everyone, I was trying to query local network of the PC I am trying to develop a sample, with Maven + Spring 3.2.5 and Vaadin Flow 24.3.12, with Java class where calling Network it should return local network like the ethernet with this code:

nets = NetworkInterface.getNetworkInterfaces();		
for (NetworkInterface netInf : Collections.list(nets)) {
	interfacesTypesList = "Display name: " + netInf.getDisplayName() + "\n";
	interfacesTypesList += "Name: " + netInf.getName() + "\n";
	//interfacesTypesList += "Type: " + netInf.getType() + "\n"; 
}

but instead to return an Intel 82579LM card , it returns:

Display name: WAN Miniport (PPTP)
Name: tunnel_32771

which means it is tunneling… is there a way to query outside the tunnel ? Thanks in advance! Cheers!

Did you see this StackOverflow question yet: java - NetworkInterface.getNetworkInterfaces() not listing all interfaces - Stack Overflow

Maybe you can try the things mentioned in the answers and see if they get you what you’re looking for.

HI @ollit.1 , thank you for your answer… but probably I missed something and I’d need a clarification… creating a Java Vaadin PWA it is possible to encapsulate also a local server in a single jar/war to execute that Java code which would query local mobile phone’s network for example connected to a WiFi to get another custom device informations? Something that can do a native app usually…

All the application logic that you write with Flow in Java runs on the server which is typically a separate server rather than a JVM on the user’s PC.

It’s in theory possible to create a native app bundle that runs a Java server on the user’s PC and then shows the UI in the user’s regular browser or wrapped in e.g. an Electron shell. This is, however, outside of the officially supported way of using Vaadin so there won’t be any documentation or such to describe how it’s done.

One possibility for some cases could be that you integrate with various JavaScript APIs provided by the browser for interacting with external devices. But I’m not sure if the browser provides access to the things that you would need.

Hi, to only way to get this properly your way is using wasm.
It’s a challenge… because you will have to wrap entire springboot and vaadin in single file. (GrallVM for ex) It is how ever possible… but don’t count on in to work in production. In Other words there are more simple ways to do so.

But if you succeed, Please share.

HI @ecohen280 , thanks for your answer! Investigating some more about WASM you suggested, like here on this site : How to run Java in the browser with WebAssembly and remembering this page in Vaadin documentation , Deploying using Docker , looks like sort of with Docker that should be possible so once compiled it should become sort of like a native android app, but this time, executed in the browser so it can be executed also on iPhone mobiles for example, right?..

For your specific goal, luckily is not possible. ( :( sorry
If it was possible, then say good by to Security.

WASM works as a separate “sandbox” it has not access to nothing, even to network. you can use it to do great your browser will have hard time to do,

so you need to build a bridge JS<>WASM.

To help you solve your goal I would suggest the following

  1. Vaadin PWA (regualr app)
  2. Create a wasm extention with JS<>WASM<>VAADIN bridge (easier then it sounds)
  3. Build the pwa permissions.

Before you start you need to be sure the devices and browser supports your
required permission.

As running Java on browser ( How to run Java in the browser with WebAssembly )

Well , technically speaking - possible.

Will it be responsive,quick, and reliable ? :sob:

Applications that need to access local resources have usaually the same architecture.

The have a small API server that must be installed on the users computer that can access all resources. Then the web application will access this API.

Antother idea if you are on Windows could be to install a protocol handler.

I think the most fundamental question here is why you would need the details of the local network in the first place? What problem you are trying to solve with that?

And based on answer to that question, could you image totally different kind of approaches to achieve the solution.

Hello Tatu Lund , thanks for your answer! I am trying to reach local network because I am planning to convert a native android app to pwa which queries custom devices connected to a Wifi network or their own hotspot to get information such as remaining battery life… so actually looking at local network which would be for example mobile wifi to obtain the mask for example 192.168.7.X and then polling from 1 to 255 sending socket query to the device fi exists there…

Actually looking around about those WASM who elad suggested earlier, seems there is a cheerpj which should work with networking as they say on their site…

Also take a look at the Web APIs: Web APIs | MDN

WASM in itself will not help you since that would still run within the security sandbox of the user’s web browser that has the same limitations as anything run as JavaScript in the browser. A raw-sockets browser API was discussed a while ago but it was not adopted and implemented by browsers. This means that the network access has to be managed through code that runs outside of the browser, i.e. as a native application or in a regular JVM.

Cheerpj’s networking support doesn’t mean you can access arbitrary networking devices from the computer that runs the browser, it means you can use http/s and websockets: Networking - CheerpJ Documentation

Hi @Nunzio_Luigi
as other suggested, it’s not possible

you can’t arp from browser, regardless the language code you are using.

in Native IOs it’s not possible any way.

HI @ecohen280 ,

in Native IOs it’s not possible any way.

you mean also in native android app? If yes, indeed I already made an android native java app which retrieves local mobile/tablet IP and from this, it queries all IPs between .1 and .255 with success… just I was thinking the possibility to convert as PWA so in the way instead to have native app only for android , a PWA would be executed also on iOS which its core is always sort-of linux as like as android…

indeed I already made an android native java app which retrieves local mobile/tablet IP and from this, it queries all IPs between .1 and .255 with success…
This is called ARP (Address Resolution Protocol).

In Android you can ask for permission to access Network
on as you already know
network data is located at

/proc/net/arp

A website and PWA does not have access for this (and they really should not)

as per IOS - only rooted devices might work?.

And in order to help you out , since it’s still Vaadin Forum :)

as @SimonMartinelli wrote check WebAPI at MDN

  1. You can build your UI interface with Vaadin web components (Ts/Js)
  2. use Apache Cordova (or other alternative) to access native components.

This is the shortest way to try.

Hi again @ecohen280!

As I said in my start post in pure Java which is Vaadin, or Android too, I use NetworkInterface.getNetworkInterfaces() which is an internal java.net.* library function and it should normally return my local network.
Just at this point I suspect maybe if I compile and create a jar file then it would be like an encapsulated system…that’s why, as I said in my start post, I obtain a result yes, which is not the local network but a Wan Miniport (PPTP), and doing ipconfig/ifconfig it doesn’t show in the system list but it could be something like a “virtual network” inside the jar maybe… that’s why I was asking for…
Even I have to say, once running it as Application on Eclipse, I got the LAN Ethernet Adapter local network too, but just I don’t remember what I did exactly to retrieve that local network of my PC…

Dear @Nunzio_Luigi , I’ve got you from the first post you wrote.

Again, this is Vaadin Forum not XDA forum

It working because you run in in emulator or developer enabled devices.

check up Kali Linux : Kali Linux on Android using Linux Deploy | Kali Linux Blog

best regards