Tuesday, December 2, 2008

Java get MAC ADDRESS

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
 
public class mac_address {
    
    public static void main(String[] args) {
        try {        
            InetAddress address = InetAddress.getLocalHost();
            
            /*
             * Get NetworkInterface for the current host and then read the
             * hardware address.
             */
            NetworkInterface ni = NetworkInterface.getByInetAddress(address);
            byte[] mac = ni.getHardwareAddress();
            System.out.println(Array.join(mac,""));
            /*
             * Extract each array of mac address and convert it to hexa with the
             * following format 08-00-27-DC-4A-9E.
             */
            for (int i = 0; i < mac.length; i++) {            
                System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
            }
            
        } catch (UnknownHostException e) {
            e.printStackTrace();    
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }    
}

Centos 7 reset root/ any user lost password / lockout due to cant remember password

1. Need to be in front of the terminal. (Physically if not vm). 2. Reboot the server 3. Press 'e' in the GRUB2 boot screen. 3. bunch...