Posts

Showing posts from March, 2019

What is the MAC address of your system?

Image
Q. Write a Java progarm in order to check the MAC Address of your system. Ans.  import java.io.*;  import java.net.*; public class mac { public static void main(String[] args)    {   InetAddress ip;   try {    ip = InetAddress.getLocalHost();    System.out.println("IP address : " + ip.getHostAddress());    NetworkInterface network = NetworkInterface.getByInetAddress(ip);    byte[] mac = network.getHardwareAddress();    System.out.print("MAC address : ");    StringBuilder sb = new StringBuilder();    for (int i = 0; i < mac.length; i++)   {     sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));    }    System.out.println(sb.toString());   }    catch (Exception e)   {    e.printStackTrace();   }  } } Output: javac mac.java (//enter) java mac (//enter)...

How Check IP Address of your system

Image
Q. Write a Java progarm in order to check the IP Address of the system. Ans. import java.io.*; import java.net.*; public class ip { public static void main(String args[])  {   try    {     InetAddress ob=InetAddress.getLocalHost();     System.out.println("IP of my system:"+ob.getHostAddress());     }    catch(IOException e)    {     System.out.println("Exception is="+e.getMessage()e.getMessage());     }   } } Output: javac ip.java  (//enter) java ip  (//enter) IP of my system: 192.168.1.21 ipconfig Windows IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix: domain.name IP Address............................: 192.168.1.14 Subnet Musk.........................: 255.255.255.0 Default Gateway....................: 192.168.1.1