下面我有一段代码
我想把他变成一个javabean
import java.lang.*;import java.io.*;import java.util.*;public class Util_syscmd { public 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) { return null; } } public void Start(String shellCommand) { try { if (p != null) { kill(); } Runtime sys = Runtime.getRuntime(); p = sys.exec(shellCommand); }
catch (Exception e) { System.out.println(e.toString()); } } public void kill() { if (p != null) { p.destroy(); p = null; } } Process p;}class GetPhysicalAddress { static private final int _physicalLength = 17;
static private final int DNS = 9; public static void main(String[] args) { System.out.println(getPhysicalAddress());
System.out.println(getDNS()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static public String getPhysicalAddress() { Util_syscmd shell = new Util_syscmd(); String cmd = "cmd.exe /c ipconfig/all"; Vector result; result = shell.execute(cmd); return parseCmd(result.toString()); } static private String parseCmd(String s) { String find = "Physical Address. . . . . . . . . :"; int findIndex = s.indexOf(find); if (findIndex == -1) return "not find"; else return s.substring(findIndex + find.length() + 1,
findIndex + find.length() + 1 + _physicalLength); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static public String getDNS() { Util_syscmd shell = new Util_syscmd(); String cmd = "cmd.exe /c ipconfig/all"; Vector result; result = shell.execute(cmd); return parseCmdDNS(result.toString()); } static private String parseCmdDNS(String s) { String findDNS = "Connection-specific DNS Suffix . :"; int findDNSIndex = s.indexOf(findDNS); if (findDNSIndex == -1) return "not find"; else return s.substring(findDNSIndex + findDNS.length() + 1,
findDNSIndex + findDNS.length() + 1 + DNS); }}
我想把他变成一个javabean
import java.lang.*;import java.io.*;import java.util.*;public class Util_syscmd { public 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) { return null; } } public void Start(String shellCommand) { try { if (p != null) { kill(); } Runtime sys = Runtime.getRuntime(); p = sys.exec(shellCommand); }
catch (Exception e) { System.out.println(e.toString()); } } public void kill() { if (p != null) { p.destroy(); p = null; } } Process p;}class GetPhysicalAddress { static private final int _physicalLength = 17;
static private final int DNS = 9; public static void main(String[] args) { System.out.println(getPhysicalAddress());
System.out.println(getDNS()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static public String getPhysicalAddress() { Util_syscmd shell = new Util_syscmd(); String cmd = "cmd.exe /c ipconfig/all"; Vector result; result = shell.execute(cmd); return parseCmd(result.toString()); } static private String parseCmd(String s) { String find = "Physical Address. . . . . . . . . :"; int findIndex = s.indexOf(find); if (findIndex == -1) return "not find"; else return s.substring(findIndex + find.length() + 1,
findIndex + find.length() + 1 + _physicalLength); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static public String getDNS() { Util_syscmd shell = new Util_syscmd(); String cmd = "cmd.exe /c ipconfig/all"; Vector result; result = shell.execute(cmd); return parseCmdDNS(result.toString()); } static private String parseCmdDNS(String s) { String findDNS = "Connection-specific DNS Suffix . :"; int findDNSIndex = s.indexOf(findDNS); if (findDNSIndex == -1) return "not find"; else return s.substring(findDNSIndex + findDNS.length() + 1,
findDNSIndex + findDNS.length() + 1 + DNS); }}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货