JSP如何取得局域网内计算机的Mac地址
我想在我的网站上建个投票系统,但是担心刷票,所以想取得所有机器的Mac地址,对于局域网内的计算机的Mac地址,怎么才能取得呢?各位大侠,帮帮我吧,谢谢
------解决方案--------------------import java.io.*; 
 import java.net.InetAddress;   
 public class  GetMac 
 { 
     //通过IP获取网卡地址 
  public String getMacByIP(String serverIP) 
  { 
   String str =  " "; 
   String macAddress =  " "; 
   try 
   {      
    Process pp = Runtime.getRuntime().exec( "nbtstat -A  "+serverIP); 
    InputStreamReader ir = new InputStreamReader(pp.getInputStream()); 
    LineNumberReader input = new LineNumberReader(ir); 
    for(int i = 1;i  < 100;i++) 
    { 
     str = input.readLine(); 
     if(str != null)  
     { 
      if(str.indexOf( "MAC Address ") >  1)  
      { 
       macAddress = str.substring(str.indexOf( "MAC Address ")+14,str.length()); 
       break; 
      } 
     } 
    } 
   } 
   catch(
IOException ex) 
   { 
    ex.printStackTrace();  
   } 
   return macAddress; 
  } 
   //通过机器名获取网卡地址 
  public String getMacByServerName(String serverName) 
  { 
   String str =  " "; 
   String macAddress =  " "; 
   try 
   {      
    Process pp = Runtime.getRuntime().exec( "nbtstat -a  "+serverName); 
    InputStreamReader ir = new InputStreamReader(pp.getInputStream()); 
    LineNumberReader input = new LineNumberReader(ir); 
    for(int i = 1;i  < 100;i++) 
    { 
     str = input.readLine(); 
     if(str != null)  
     { 
      if(str.indexOf( "MAC Address ") >  1)  
      { 
       macAddress = str.substring(str.indexOf( "MAC Address ")+14,str.length()); 
       break; 
      } 
     } 
    } 
   } 
   catch(IOException ex) 
   { 
    ex.printStackTrace();  
   } 
   return macAddress; 
  }     
  public static void main(String[] args)  
    { 
  	try 
 	{   
  	        GetMac getmac; 
  	        getmac=new GetMac(); 
  	        String mac= " "; 
  	        mac=getmac.getMacByIP( "192.168.1.57 "); 
  	        System.out.println(mac); 
  	        mac=getmac.getMacByServerName( "server "); 
  	        System.out.println(mac); 
 	} 
  	catch( Exception e ) 
 	{ 
  		System.out.println( e.getMessage() ); 
 	} 
     } 
 } 
 供你参考