Advertisements

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[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
NetworkInterface nwi = NetworkInterface.getByInetAddress(address);
byte mac[] = nwi.getHardwareAddress();
System.out.println(mac);
}
catch(Exception e)
{
System.out.println(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

Advertisements

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…

Like

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

Like

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

Like

Thanks.

But I would suggest you to change your name!

Like

Get MAC Address using Java…

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

Like

Thanks JavaPins for sharing this post on to your site.

Like

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

Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Advertisements

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

Join 8,305 other followers

Tweets

%d bloggers like this: