Link to home
Start Free TrialLog in
Avatar of penang67
penang67

asked on

Java read machine address

Dear all, i am planning to use the machine address to be the unique character to determine my licensing program.

I have code this code,

      Enumeration enu = NetworkInterface.getNetworkInterfaces();
                  while (enu.hasMoreElements()){
                        System.out.println(enu.nextElement());
                  }
..
..

**********
name:lo (MS TCP Loopback interface) index: 1 addresses:
/127.0.0.1;

name:eth0 (Realtek RTL8168/8111 PCI-E Gigabit Ethernet NIC - Packet Scheduler Miniport) index: 2 addresses:
/11.11.10.29;

name:eth1 (Bluetooth PAN Network Adapter - Packet Scheduler Miniport) index: 65540 addresses:
/121.145.50.1;

*****************

and it's doesn't seems what i am looking for.
What i am looking is something which is unique and the best in mind is the Network Interface Card number.

Can you help??

Avatar of cmalakar
cmalakar
Flag of India image

InetAddress netaddr = InetAddress.getLocalHost();
netaddr.getHostName(); // will return the hostname
netaddr.getHostAddress(); // will return the host ip address
or else You can use..

getHardwareAddress()  api of NetworkInterface class
Avatar of penang67
penang67

ASKER

the  InetAddress doesn't have the get MAC address method.
getHardwareAddress() returns the MAC Address

But it is available from jdk 1.6 version..

If you want to get the MAC Address in < 1.6 version..

Then you have execute os command using

Runtime.exec("oscommand") and grep from the MAC address from the output
can you show how to get it from getHardwareAddress() from the inetaddr???
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cmalakar, thanks for your help. Can you help to explain, how is this statement mean??

 String temp = Integer.toHexString(b[i] & 0xff);

the toHexString(int i) how come become b[i] & 0xff and why '0Xff'??

thanks