formsUitl.java
package formsUtil;
import java.net.InetAddress;import java.net.NetworkInterface;
import oracle.forms.ui.VBean;import oracle.forms.handler.IHandler;import oracle.forms.properties.ID;
/* * * In Forms: BL.INFOS := Get_Custom_Property('CONTROL.BEAN', 1, 'GET_IP_ADDRESS' ) ; */
@SuppressWarnings("serial")public class formsUitl extends VBean {
/* * Define variables */ private static final ID MACHINE_NAME = ID.registerProperty("GET_MACHINE_NAME"); private static final ID IP_ADDRESS = ID.registerProperty("GET_IP_ADDRESS"); private static final ID MAC_ADDRESS = ID.registerProperty("GET_MAC_ADDRESS"); private static final ID OS_NAME = ID.registerProperty("GET_OS_NAME"); private static final ID ARCHITECTURE = ID.registerProperty("GET_ARCHITECTURE"); private static final ID OS_VERSION = ID.registerProperty("GET_OS_VERSION"); private static final ID USER_NAME = ID.registerProperty("GET_USER_NAME"); private static final ID USER_HOME = ID.registerProperty("GET_USER_HOME");
/* * Initialize forms handler */ public void init(IHandler handler) { super.init(handler); }
/* * Get property */ public Object getProperty(ID pId) { if (pId != null) { return getMachineInfo(pId); } else { return super.getProperty(pId); } } /* * getMachineInfo() */ private final static String getMachineInfo(ID pId) { try { InetAddress ip = InetAddress.getLocalHost(); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder();
if (pId == MACHINE_NAME) { return ip.getHostName(); } else if (pId == IP_ADDRESS) { return ip.getHostAddress(); } else if (pId == MAC_ADDRESS) { for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } return sb.toString(); } else if (pId == OS_NAME) { return System.getProperty("os.name"); } else if (pId == ARCHITECTURE) { return System.getProperty("os.arch"); } else if (pId == OS_VERSION) { return System.getProperty("os.version"); } else if (pId == USER_NAME) { return System.getProperty("user.name"); } else if (pId == USER_HOME) { return System.getProperty("user.home"); } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } }
/* * Main method for Test */ public static void main(String[] args) { try { System.out.println("Host Name: " + getMachineInfo(MACHINE_NAME)); System.out.println("IP Address: " + getMachineInfo(IP_ADDRESS)); System.out.println("MAC Address: " + getMachineInfo(MAC_ADDRESS)); System.out.println("OS Name: " + getMachineInfo(OS_NAME)); System.out.println("Architecture: " + getMachineInfo(ARCHITECTURE)); System.out.println("OS Version: " + getMachineInfo(OS_VERSION)); System.out.println("User Name: " + getMachineInfo(USER_NAME)); System.out.println("User Home: " + getMachineInfo(USER_HOME)); } catch (Exception e) { e.printStackTrace(); } }}
댓글 없음:
댓글 쓰기