0

first i get mac address from pc client like this

public void getterMacAddress(){
      InetAddress ip;
    try {

        ip = InetAddress.getLocalHost();
        System.out.println("Current IP address : " + ip.getHostAddress());

        NetworkInterface network = NetworkInterface.getByInetAddress(ip);

        byte[] mac = network.getHardwareAddress();

        System.out.print("Current MAC address : ");

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mac.length; i++) {
            sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));        
        }
        System.out.println(sb.toString());
                macAddress = sb.toString();

    } catch (UnknownHostException e) {

        e.printStackTrace();

    } catch (SocketException e){

        e.printStackTrace();

    }
    }

i get the mac address successfull, but how i can send that mac address to server?

Yusuf1494
  • 252
  • 1
  • 5
  • 16
  • What do you mean sending it to the server. When you deploy the application on the server, its already there. You just need to read it – Shervin Asgari Apr 15 '13 at 09:38

1 Answers1

0

You may pass a String to server(JSF) as URL parameter

myserver:port/myproject/innerpage/mac.jsf?mac=5C-AC-4C-75-44-4A

public class Bean {

@ManagedProperty(value="#{param.mac}")
private String mac;

@PostConstruct
public void init() {
    System.out.println(mac); // 5C-AC-4C-75-44-4A
}
// ...
}

Also look at this question: parameter in URL jsf2

I do not recommend using JSF for this purpose. Servlet or REST web sevice - is a better way.

Community
  • 1
  • 1
uzvar
  • 71
  • 1
  • 5