Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Learn by Example - Java Sample Programs

Address Resolution Protocol in Java

Book navigation

  • Armstrong Number
  • Palindrome Checking
  • Playing Audio Clip using Applet
  • Applet Form
  • Exception Handling
  • Multiple Inheritance and Packages
  • Shopping List
  • Simple Multithread program
  • JDBC Program Select, Insert, Update, Delete records
  • RMI - Example AddServer
  • Simple Bank Account Process
  • TCP Server and Client in Java
  • UDP Server and Client in Java
  • FTP Server and Client in Java
  • Chat Server and Client in Java
  • Echo Server and Client in Java
  • Address Resolution Protocol in Java
  • Ping server and Client in Java
  • Multicast Server and Client in Java
  • Transposition Cipher Method
  • Poly-alphabetic Cipher Method Encryption - Java
  • DES - Using Data Encryption Standard in Java
  • AES - Using Advanced Encryption Standard in Java
  • Bit Stuffing
By Karthikeyan , 3 November, 2012
This program displays the MAC address of the network interface.
This program accepts the System name in LAN as Input and displays the IP Address and Physics Address of the system.

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Scanner;

public class MacAddress {
    public static void main(String[] args)
    {
        try
        {
            Scanner console = new Scanner(System.in);
            System.out.println("Enter System Name: ");
            String ipaddr = console.nextLine();
            InetAddress address = InetAddress.getByName(ipaddr);
            System.out.println("address = "+address);
            NetworkInterface ni = NetworkInterface.getByInetAddress(address);
            if (ni!=null)
            {
                byte[] mac = ni.getHardwareAddress();
                if (mac != null)
                {
                    System.out.print("MAC Address : ");
                    for (int i=0; i < mac.length; i++)
                    {
                        System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" :"");
                    }
                }
                else
                {
                    System.out.println("Address doesn't exist or is not accessible/");
                    
                    }
                }
            else
            {
                System.out.println("Network Interface for the specified address is not found");
            }
        }
        catch(UnknownHostException | SocketException e)
        {
        }
    }    
}

Sample output


Enter System Name: 
myhomepc
address = myhomepc/169.254.189.225
MAC Address : 08-00-27-00-C4-03
  • Add new comment

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy