import java.io.*;
import java.util.*;public class MACHomework
{
static private final int MACLength=18;
public static void main(String args[])
{
System.out.print ("本机的物理地址是:");
System.out.println(getMACAddress());
}
static public String getMACAddress()
{
SysCommand syscmd=new SysCommand();
//系统命令
String cmd="cmd.exe /c ipconfig/all";
Vector result;
result=syscmd.execute(cmd);
return getCmdStr(result.toString());
}
static public String getCmdStr(String outstr)
{
String find="Physical Address. . . . . . . . . :";
int findIndex=outstr.indexOf(find);
if(findIndex==-1)
{
return "未知错误!";
}
else
{
return outstr.substring(findIndex+find.length()+1,findIndex+find.length()+MACLength);
}
}
}//SysCommand类
class SysCommand
{
Process p;
public Vector execute(String cmd)
{
try
{
Start(cmd);
Vector vResult=new Vector();
DataInputStream in=new DataInputStream(p.getInputStream());
BufferedReader myReader=new BufferedReader(new InputStreamReader(in));
String line;
do
{
line=myReader.readLine();
if(line==null)
{
break;
}
else
{
vResult.addElement(line);
}
}while(true);
myReader.close();
return vResult;
}
catch(Exception e)
{
return null;
} }
public void Start(String cmd)
{
try
{
if(p!=null)
{
kill();
}
Runtime sys=Runtime.getRuntime();
p=sys.exec(cmd);
}
catch(Exception e)
{
}
}
public void kill()
{
if(p!=null)
{
p.destroy ();
p=null;
}
}
}
import java.util.*;public class MACHomework
{
static private final int MACLength=18;
public static void main(String args[])
{
System.out.print ("本机的物理地址是:");
System.out.println(getMACAddress());
}
static public String getMACAddress()
{
SysCommand syscmd=new SysCommand();
//系统命令
String cmd="cmd.exe /c ipconfig/all";
Vector result;
result=syscmd.execute(cmd);
return getCmdStr(result.toString());
}
static public String getCmdStr(String outstr)
{
String find="Physical Address. . . . . . . . . :";
int findIndex=outstr.indexOf(find);
if(findIndex==-1)
{
return "未知错误!";
}
else
{
return outstr.substring(findIndex+find.length()+1,findIndex+find.length()+MACLength);
}
}
}//SysCommand类
class SysCommand
{
Process p;
public Vector execute(String cmd)
{
try
{
Start(cmd);
Vector vResult=new Vector();
DataInputStream in=new DataInputStream(p.getInputStream());
BufferedReader myReader=new BufferedReader(new InputStreamReader(in));
String line;
do
{
line=myReader.readLine();
if(line==null)
{
break;
}
else
{
vResult.addElement(line);
}
}while(true);
myReader.close();
return vResult;
}
catch(Exception e)
{
return null;
} }
public void Start(String cmd)
{
try
{
if(p!=null)
{
kill();
}
Runtime sys=Runtime.getRuntime();
p=sys.exec(cmd);
}
catch(Exception e)
{
}
}
public void kill()
{
if(p!=null)
{
p.destroy ();
p=null;
}
}
}
TCP/IP协议中写得很明白,接收终端收到的数据包中的MAC地址是最后一个路由器的MAC地址,而不是发送终端的MAC地址。而IP之上的TCP和HTTP更不会附带MAC地址的信息了。
所以只靠服务器是绝对没有可能的,只能在客户端安装程序。书上看到的只可能是这种情况。
----------------------------------------------------
同意该观点!
不过实现方法可以参考上面的.