简体   繁体   中英

Get mac from client

I am trying to collect a building's mac addresses, and I have created a web application using Vaadin 6(the application has other features so I have to stick with vaadin).

The problem is, I want my user to only insert his name, and for me to get his mac address automatically, but the problem is I don't know how to do it.

I was using

ip = InetAddress.getLocalHost();
mac = ip.getHostAddress();

The problem is that this code returns me my own servers ip and mac.

So the question is, how can I get the client's mac address??

Also if i can get the local ip that is so much better, but first I need the mac.

Any help is very much appreciated.

IP address of the client in a servlet you can get so -

HttpServletRequest httpServletRequest = (HttpServletRequest) request;

// Proxy
String userIpAddress = httpServletRequest.getHeader("X-Forwarded-For");

if(userIpAddress == null) {
   userIpAddress = request.getRemoteAddr();
}

In Vaadin there are class WebBrowser , you can use it -

WebBrowser browser = (WebBrowser) getWindow().getTerminal();
String userIpAddress = browser.getAddress();

MAC address of sender changing as many times as times the frame passes through routers and you will always receive the MAC address of the network gateway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM