如题

解决方案 »

  1.   

    不能直接取,但是可以调用系统方法然后读取字符.
    使用Runtime 和Process联合使用.
      

  2.   

    谢谢楼上的,限于小虾米的实力,能否给点详细的代码例子. 我是做的一个网上注册系统,需要提取客户端的mac地址来进行生成序列号.
      

  3.   

    package cn.ccbyn.ywb;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */
    import java.util.Vector;
    import java.io.*;public class test {
      public test() {
      }  Process p;
      private Vector execute(String shellCommand){
        try{
          Start(shellCommand);
          Vector vResult=new Vector();
          DataInputStream in=new DataInputStream(p.getInputStream());
          BufferedReader reader=new BufferedReader(new
                      InputStreamReader(in));
          String line;
          do{
            line=reader.readLine();
            if (line==null){
              break;
            }
            else{
              vResult.addElement(line);
            }
          }while(true);
          reader.close();
          return vResult;    }catch(Exception e){
        //error
        return null;
        }
      }
      private void Start(String shellCommand){
        try{
          if(p!=null){
            p.destroy();
            p=null;
          }
          Runtime sys= Runtime.getRuntime();
          p=sys.exec(shellCommand);
        }catch(Exception e){
          System.out.println(e.toString());
        }
      }//取得网卡地址
      private String getMacAddress(){
        String cmd;
        if (!System.getProperty("os.name").equals("Windows NT")){
          cmd = new String("cmd.exe /c ipconfig /all");
        }
        else{
          cmd = new String("command.com /c ipconfig /all");
        }
        Vector resultCmd = this.execute(cmd);
        return parseCommand(resultCmd.toString());
      }  //从字符串中解析出所需要获得的字符串
       private String parseCommand(String s){
         String find = "Physical Address. . . . . . . . . :";
         int findIndex = s.indexOf(find);
         if (findIndex != -1)
           return s.substring(findIndex + find.length() + 1,
                              findIndex + find.length() + 1 + 17);
         else {
           return "not find macAddress";
         }
       }
      public static void main(String[] args) {
        test test1 = new test();
        System.out.print(test1.getMacAddress());
      }}
      

  4.   

    如果楼上的例子可以的话。。那我就在我的jsp里,加上 format c: 嘿嘿。。
      

  5.   

    是可以的 可以调用format c:
      

  6.   

    // 文件名为 NetTool.java  
    import java.net.*; 
    public class NetTool{ 
    InetAddress myIPaddress=null; 
    InetAddress myServer=null; public static void main( String args[]){ NetTool mytool; 
    mytool=new NetTool(); System.out.println("Your host IP is: " 
    + mytool.getMyIP()); 
    System.out.println("The Server IP is :" 
    +mytool.getServerIP()); } //取得LOCALHOST的IP地址 
    public InetAddress getMyIP() { 
    try { myIPaddress=InetAddress.getLocalHost();} 
    catch (UnknownHostException e) {} 
    return (myIPaddress); 

    //取得 www.abc.com 的IP地址 
    public InetAddress getServerIP(){ 
    try {myServer=InetAddress.getByName( 
    "www.abc.com");} 
    catch (UnknownHostException e) {} 
    return (myServer); 
    } } ---- 由于JAVA语言的跨平台特性,以上程序编译后可直接在任何装有JVM系统的机器上运行。以上程序旨在抛砖引玉,读者可将上述代码稍加变换转化成APPLET加到你的homepage中,或将地址查询结果写到一个文件中去,建立自己本地的hosts文件。 
      

  7.   

    上面提供想 format c的朋友,你们想过,你们format 的是谁的机子吗。有一点是肯定的,它不会是客户端的机子。