Skip to content

Commit

Permalink
Merge pull request Ishaan28malik#611 from suraj7086/master
Browse files Browse the repository at this point in the history
Finding MAC Address
  • Loading branch information
Ishaan28malik authored Oct 22, 2020
2 parents 001f76a + d280fa5 commit c4b3985
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions FindMacAdress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.net.NetworkInterface;

public class Mac_Address {
public static void main(String[] args) throws UnknownHostException {
InetAddress ip;
InetAddress addr = InetAddress.getLocalHost();
try {
String hostname = addr.getHostName();
System.out.println("Host Name : " + hostname);

ip = InetAddress.getLocalHost();
System.out.println("Current IP address : " + ip.getHostAddress());

NetworkInterface network = NetworkInterface.getByInetAddress(ip);

byte[] mac = network.getHardwareAddress();

System.out.print("Current 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();

}

}
}



0 comments on commit c4b3985

Please sign in to comment.