Import java.io. *; import java.util. *;
Public Class Machomework {static private final int macLength = 18; public static void main (string args []) {system.out.print ("The physical address of this machine is:"); system.out.println (getmacaddress ()) ;} static public String getMACAddress () {SysCommand syscmd = new SysCommand (); // system command 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 Findex = Outstr.Indexof (Find); if -1) {Return "unknown error!";} Else {return outstr.substring (FindIndex Find.Length () 1, FindIndex Find.Length () Maclength);}}}
// SysCommand class 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 (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;}}}