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??

penang67Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

getHardwareAddress()  api of NetworkInterface class
0
penang67Author Commented:
the  InetAddress doesn't have the get MAC address method.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

cmalakarCommented:
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
0
penang67Author Commented:
can you show how to get it from getHardwareAddress() from the inetaddr???
0
cmalakarCommented:
This will work only in jdk 1.6 .. !
InetAddress netaddr = InetAddress.getLocalHost();
NetworkInterface intf = NetworkInterface.getByInetAddress(netaddr);
byte[] b = intf.getHardwareAddress();
 
for(int i = 0; i < b.length; i++)
{
  String temp = Integer.toHexString(b[i] & 0xff);
  temp = temp.length() > 1 ? temp : "0" + temp;
  System.out.print(temp + " "); //Prints the bytes of mac address
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
penang67Author Commented:
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
0
cmalakarCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.