0 Replies Latest reply: Dec 13, 2012 10:57 PM by user2040934 RSS

    how to pick wireless physical address of client machine

    user2040934
      Dear memebers,

      Using the follwoing tutorail, I have picked the network card address ( MAC Address ).

      [forms java beans|http://forms.pjc.bean.over-blog.com/article-15985856.html]

      but this code dont' display / return the MAC address of wireless network card.

      the java code is here:
      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;
           }
           
           
      
      }
       
      how to pick the wireless physical address?


      Regards: