Skip to main content

Java Code to Get MAC Address From Target IP Address

MAC Address is a Unique identification of a Device. Computer, Mobile, Tablet, PC all have a Unique MAC Address. If you want to know about MAC Address here is some, MAC on Wiki. MAC Address is generally 48 bits long eg, 00:ff:a3:f0:76:ae
Here we are going to discuss about How to get that address by using supplied IP Address over the network.
Here is the Java Code

import java.util.Arrays;

import jpcap.*;
import jpcap.packet.*;

public class GetMACAddress{
    public static byte[] arp(InetAddress ip) throws{
        //find network interface
        NetworkInterface[] devices=JpcapCaptor.getDeviceList();
        NetworkInterface device=null;

loop:    for(NetworkInterface d:devices){
            for(NetworkInterfaceAddress addr:d.addresses){
                if(!(addr.address instanceof Inet4Address)) continue;
                byte[] bip=ip.getAddress();
                byte[] subnet=addr.subnet.getAddress();
                byte[] bif=addr.address.getAddress();
                for(int i=0;i<4;i++){
                    break loop;
            throw new IllegalArgumentException(ip+" is not a local address");
        //open Jpcap
        JpcapCaptor captor=JpcapCaptor.openDevice(device,2000,false,3000);
        JpcapSender sender=captor.getJpcapSenderInstance();
        InetAddress srcip=null;
        for(NetworkInterfaceAddress addr:device.addresses)
            if(addr.address instanceof Inet4Address){

        byte[] broadcast=new byte[]{(byte)255,(byte)255,(byte)255,(byte)255,(byte)255,(byte)255};
        ARPPacket arp=new ARPPacket();
        EthernetPacket ether=new EthernetPacket();
            ARPPacket p=(ARPPacket)captor.getPacket();
                throw new IllegalArgumentException(ip+" is not a local address");
                return p.sender_hardaddr;
    public static void main(String[] args) throws Exception{
            System.out.println("Usage: java GetMACAddress <ip address>");
            byte[] mac=GetMACAddress.arp(InetAddress.getByName(args[0]));
            for (byte b : mac)
                System.out.print(Integer.toHexString(b&0xff) + ":");

To run this you need to get a library called WinPCap from for Windows or LibPCap for Linux. And more over you need to get a Java Library JPCap from Click Here .

If you have both these Library installed on your system then you can compile and run.

E:\>java GetMACAddress

This is How you can get a MAC address from any machines from your Network/LAN.


  1. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    mobile application development training online
    mobile app development course
    mobile application development course
    learn mobile application development
    mobile app development training
    app development training
    mobile application development training
    mobile app development course online
    online mobile application development

  2. thanks for your information really good and very nice web design company in velachery

  3. You are providing a post is very useful for develop my knowledge and I learn more info from your blog.
    Digital Marketing Course In Kolkata
    Web Design Course In Kolkata
    SEO Course In Kolkata

  4. Way cool! lap Some very valid points! I appreciate you penning this write-up plus the rest of the website is really good.

  5. Hello! I just now would like to supply a massive thumbs up for any wonderful information you could have here within this post. We are coming back to your blog post for further soon. good luck
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai


  6. Thanks of sharing this post…Python is the fastest growing language that helps to get your dream job in a developing area. It says every fundamental in a programming, so if you want to become an expertise in python get some training

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

  7. Salesforce CRM software will help companies have a brief overview about how their competitors in the similar niche are performing and thereby helping them in developing a solution that would help in efficient management. Salesforce interview questions and answers


Post a Comment