Results 1 to 1 of 1
- 12-14-2012, 06:35 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
how to pick wireless physical address of client machine?
Dear memebers,
I am Oracle Developer, new to java, here is a java file with the help of this I could be able to pick the MAC addrees / physical address of the client machine.
But this code don't pick the wireless lan card physical address, can anyone help me to add this functionality to this code.
[forms java beans|http://forms.pjc.bean.over-blog.com/...15985856.html]
the java code is here:
Regards:Java Code:package oracle.forms.fd; import java.net.InetAddress; import java.io.InputStream; import java.io.BufferedInputStream; import java.io.IOException; import java.text.ParseException; import java.util.StringTokenizer; import oracle.forms.ui.VBean; import oracle.forms.handler.IHandler; import oracle.forms.properties.ID; /** * A Java Bean that returns Client machine info * * code found on the java forum * http://forum.java.sun.com/thread.jspa?threadID=655913 * * @author Francois Degrelle (wrapper) * @version 1.1 * */ public final class ClientInfos extends VBean { private static final ID GETINFOS = ID.registerProperty("GET_CLIENT_INFOS"); private static final ID GETINFO = ID.registerProperty("GET_CLIENT_INFO"); private static final ID Operating = ID.registerProperty("OPERATING"); private static final ID architecture = ID.registerProperty("ARCHITECTURE"); private static final ID osVersion = ID.registerProperty("OSVERSION"); private static final ID IP = ID.registerProperty("IP"); private static final ID MAC = ID.registerProperty("MAC"); private static final ID javaVersion = ID.registerProperty("JAVAVERSION"); private static final ID javaVendor = ID.registerProperty("JAVAVENDOR"); private static final ID javaVendorUrl = ID.registerProperty("JAVAVENDORURL"); private static final ID javaHome = ID.registerProperty("JAVAHOME"); private static final ID javaVmSpecificationVersion = ID.registerProperty("JAVAVMSPECIFICATIONVERSION"); private static final ID javaVmSpecificationVendor = ID.registerProperty("JAVAVMSPECIFICATIONVENDOR"); private static final ID javaVmSpecificationName = ID.registerProperty("JAVAVMSPECIFICATIONNAME"); private static final ID userName = ID.registerProperty("USERNAME"); private static final ID userHome = ID.registerProperty("USERHOME"); private String sInfos = ""; private String sOperating = ""; private String sarchitecture = ""; private String sosVersion = ""; private String sIP = ""; private String sMAC = ""; private String sjavaVersion = ""; private String sjavaVendor = ""; private String sjavaVendorUrl = ""; private String sjavaHome = ""; private String sjavaVmSpecificationVersion = ""; private String sjavaVmSpecificationVendor = ""; private String sjavaVmSpecificationName = ""; private String suserName = ""; private String suserHome = ""; private boolean bInit = false ; public void init(IHandler handler) { super.init(handler); try { sOperating = System.getProperty("os.name"); sarchitecture = System.getProperty("os.arch"); sosVersion = System.getProperty("os.version"); sIP = InetAddress.getLocalHost().getHostAddress(); sMAC = getMacAddress(); sjavaVersion = System.getProperty("java.version"); sjavaVendor = System.getProperty("java.vendor"); sjavaVendorUrl = System.getProperty("java.vendor.url"); sjavaHome = System.getProperty("java.home"); sjavaVmSpecificationVersion = System.getProperty("java.vm.specification.version"); sjavaVmSpecificationVendor = System.getProperty("java.vm.specification.vendor"); sjavaVmSpecificationName = System.getProperty("java.vm.specification.name"); suserName = System.getProperty("user.name"); suserHome = System.getProperty("user.home"); } catch(Throwable t) { t.printStackTrace(); } } public Object getProperty(ID pId) { if(pId == GETINFOS) { sInfos = "Operating System:" + sOperating ; sInfos += "\nOperating system architecture:" + sarchitecture ; sInfos += "\nOperating system version:" + sosVersion ; sInfos += "\nIP/Localhost:" + sIP ; sInfos += "\nMAC Address:" + sMAC ; sInfos += "\nJava Version:" + sjavaVersion ; sInfos += "\nJava Vendor:" + sjavaVendor ; sInfos += "\nJava vendor URL:" + sjavaVendorUrl ; sInfos += "\nJava installation directory:" + sjavaHome ; sInfos += "\nJava Virtual Machine specification version:" + sjavaVmSpecificationVersion; sInfos += "\nJava Virtual Machine specification vendor:" + sjavaVmSpecificationVendor; sInfos += "\nJava Virtual Machine specification name:" + sjavaVmSpecificationName; sInfos += "\nUser Name:" + suserName; sInfos += "\nUser's home directory:" + suserHome ; return sInfos ; } else if(pId == Operating) return sOperating; else if(pId == architecture) return sarchitecture ; else if(pId == osVersion) return sosVersion ; else if(pId == IP) return sIP ; else if(pId == MAC) return sMAC ; else if(pId == javaVersion) return sjavaVersion ; else if(pId == javaVendor) return sjavaVendor ; else if(pId == javaVendorUrl) return sjavaVendorUrl ; else if(pId == javaHome) return sjavaHome ; else if(pId == javaVmSpecificationVersion) return sjavaVmSpecificationVersion ; else if(pId == javaVmSpecificationVendor) return sjavaVmSpecificationVendor ; else if(pId == javaVmSpecificationName) return sjavaVmSpecificationName ; else if(pId == userName) return suserName ; else if(pId == userHome) return suserHome ; return super.getProperty(pId); } private final static String getMacAddress() throws IOException { String os = System.getProperty("os.name"); try { if(os.startsWith("Windows")) { return windowsParseMacAddress(windowsRunIpConfigCommand()); } else if(os.startsWith("Linux")) { return linuxParseMacAddress(linuxRunIfConfigCommand()); } else { throw new IOException("unknown operating system: " + os); } } catch(ParseException ex) { ex.printStackTrace(); throw new IOException(ex.getMessage()); } } /* * Linux stuff */ private final static String linuxParseMacAddress(String ipConfigResponse) throws ParseException { String localHost = null; try { localHost = InetAddress.getLocalHost().getHostAddress(); } catch(java.net.UnknownHostException ex) { ex.printStackTrace(); throw new ParseException(ex.getMessage(), 0); } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while(tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); boolean containsLocalHost = line.indexOf(localHost) >= 0; // see if line contains IP address if(containsLocalHost && lastMacAddress != null) { return lastMacAddress; } // see if line contains MAC address int macAddressPosition = line.indexOf("HWaddr"); if(macAddressPosition <= 0) continue; String macAddressCandidate = line.substring(macAddressPosition + 6).trim(); if(linuxIsMacAddress(macAddressCandidate)) { lastMacAddress = macAddressCandidate; continue; } } ParseException ex = new ParseException ("cannot read MAC address for " + localHost + " from [" + ipConfigResponse + "]", 0); ex.printStackTrace(); throw ex; } private final static boolean linuxIsMacAddress(String macAddressCandidate) { // TODO: use a smart regular expression if(macAddressCandidate.length() != 17) return false; return true; } private final static String linuxRunIfConfigCommand() throws IOException { Process p = Runtime.getRuntime().exec("ifconfig"); InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer= new StringBuffer(); for (;;) { int c = stdoutStream.read(); if (c == -1) break; buffer.append((char)c); } String outputText = buffer.toString(); stdoutStream.close(); return outputText; } /* * Windows stuff */ private final static String windowsParseMacAddress(String ipConfigResponse) throws ParseException { String localHost = null; try { localHost = InetAddress.getLocalHost().getHostAddress(); } catch(java.net.UnknownHostException ex) { ex.printStackTrace(); throw new ParseException(ex.getMessage(), 0); } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while(tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); // see if line contains IP address if(line.endsWith(localHost) && lastMacAddress != null) { return lastMacAddress; } // see if line contains MAC address int macAddressPosition = line.indexOf(":"); if(macAddressPosition <= 0) continue; String macAddressCandidate = line.substring(macAddressPosition + 1).trim(); if(windowsIsMacAddress(macAddressCandidate)) { lastMacAddress = macAddressCandidate; continue; } } ParseException ex = new ParseException("cannot read MAC address from [" + ipConfigResponse + "]", 0); ex.printStackTrace(); throw ex; } private final static boolean windowsIsMacAddress(String macAddressCandidate) { // TODO: use a smart regular expression if(macAddressCandidate.length() != 17) return false; return true; } private final static String windowsRunIpConfigCommand() throws IOException { Process p = Runtime.getRuntime().exec("ipconfig /all"); InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer= new StringBuffer(); for (;;) { int c = stdoutStream.read(); if (c == -1) break; buffer.append((char)c); } String outputText = buffer.toString(); stdoutStream.close(); return outputText; } }
Similar Threads
-
get client physical RAM
By loopax in forum New To JavaReplies: 0Last Post: 09-12-2012, 03:21 PM -
Java program to ping remote machine using IP address..?
By prabhurangan in forum New To JavaReplies: 19Last Post: 11-22-2011, 03:58 PM -
How to get IP address of Virtual machine
By Yogesh_P in forum NetworkingReplies: 0Last Post: 03-29-2011, 05:19 AM -
How to get IP Address of the client
By Java Tip in forum java.netReplies: 0Last Post: 04-05-2008, 10:14 AM -
Getting address of Local Machine
By Java Tip in forum Java TipReplies: 0Last Post: 11-24-2007, 07:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks