08
Apr

Common utilites to probe current system’s capabilities

Following code snippet can be used to capture few of capabilities of System under test:

package com.allstate.utilities;

import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SystemProperties {

private InetAddress localhost;

public InetAddress getLocalhost() {
return this.localhost;
}

public static String getSystemIP() throws UnknownHostException {
return InetAddress.getLocalHost().getHostAddress().trim();
}

public static String getHostName() throws UnknownHostException {
return InetAddress.getLocalHost().getHostName().trim();
}

public static String getCanonicalHostName() throws UnknownHostException {

return InetAddress.getLocalHost().getCanonicalHostName().trim();
}

public static String getLocalTime() {
Date date = new Date();
return new SimpleDateFormat(“yyyy.MM.dd HH:mm:ss”).format(date);

}

public static String getMacAddresS() throws SocketException, UnknownHostException {
InetAddress ip = InetAddress.getLocalHost();

NetworkInterface network = NetworkInterface.getByInetAddress(ip);

byte[] mac = network.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } return sb.toString(); } public static String getScreenResolution() { Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); short width = (short) size.getWidth(); short height = (short) size.getHeight(); String screenResolution = width +" x "+height; return screenResolution; } }