3

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.

3
  • @user2511414 You can get the MAC address by IP address; and, rather than being 'really unlogical', it is a fundamental operation or the ARP protocol of TCP/IP. However it can only be done for IP addresses on the same subnet. The real question here is 'for what purpose'? There's nothing useful you can do with a MAC address in Java except display it somewhere. Commented Oct 23, 2013 at 22:03
  • @EJP good point, i just didn't the scope of the work and I meant the internet. Commented Oct 23, 2013 at 22:08
  • Ejp, i need the mac adresss for my firewall, everybody will get a static ip, and with the mac i identify the pc. So mayby you can post the solution on how to get that mac? Commented Oct 24, 2013 at 4:17

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the reply. I didn't really understant the part with the mac and what it does betwen the nodes. What if I have a server on the lan, then teoreticaly the connection would be direct right?, could I get the mac then?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.