Aatul Palandurkar

Get MAC Address using Java

Posted on: June 11, 2012

Free Source Code

Free Source Code

Objective :

* How to get the MAC Address of a computer?
* How to get the MAC Address of a computer using Java?
* How to get the MAC Address of a computer via programming?

import java.net.*;

class GetMac
public static void main(String arg[])
InetAddress address = InetAddress.getLocalHost();
NetworkInterface nwi = NetworkInterface.getByInetAddress(address);
byte mac[] = nwi.getHardwareAddress();
catch(Exception e)

Note : This code will return only the first net address; if you need other detils too, get a list.

Posted from WordPress for Android

10 Responses to "Get MAC Address using Java"

not run in divices with more than one ethernet driver. sample: ethernet0 local address and wireless network.

El codigo no funciona en equipos con mas de un driver de red. O sea, si el dispositivo tiene red inalambrica y red lan, si alguno de ellos no esta coenctado no funcionara en la mayoria de los casos, para eso se debe buscar cual de ellos es el que necesita y obtener la direccion mac de ahi… suerte…


good to see blog like this.. thanks for sharing.. 🙂


Awesome blog.
If you could indent your code it would be much more readable.



But I would suggest you to change your name!


Get MAC Address using Java…

Thank you for submitting this cool story – Trackback from JavaPins…


Thanks JavaPins for sharing this post on to your site.


System.out.println on a byte[] won’t give you useful output…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13,209 other followers




%d bloggers like this: