Commit 4bf5d6ee by 焦荣

修改客户端采集功能

parent af523683
......@@ -117,44 +117,41 @@ public class SysUitl {
return mac;
}
/*获取服务器端的MAC
public static String getMacAddress()
{
//根据 nbtstat -A 通过客户端IP获取MAC
public static String getkhdMac(String ip){
String mac = "";
String line = "";
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows"))
{
try
{
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));
while((line = br.readLine()) != null)
{
System.out.println("==www=" + line);
//if (line.indexOf("Physical Address" ) > 0)
if (line.indexOf("物理地址" ) > 0 || line.indexOf("Physical Address" )>0)
{
int index = line.indexOf(":") + 2;
mac = line.substring(index);
break;
try {
Process p = null;
try {
String comstr = "nbtstat -A " + ip ;
p = Runtime.getRuntime().exec(comstr);
} catch (IOException e) {
e.printStackTrace();
}
InputStreamReader ir = new InputStreamReader(p.getInputStream(), "GBK");
LineNumberReader input = new LineNumberReader(ir);
p.waitFor();
boolean flag = true;
while(flag) {
String str = input.readLine();
// MAC 地址 = 48-8A-D2-42-5C-D8
if (str!=null && str.indexOf("MAC") > 1) {
int start = str.indexOf("=");
if (start != -1) {
mac = str.substring(start + 1).trim();
}
break;
}else if(str==null){
break;
}
br.close();
} catch (IOException e) {}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
return mac;
}*/
}
//获取MAC地址的方法
//获取服务端MAC地址的方法
public static String getMACAddress(){
//获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
byte[] mac = new byte[0];
......@@ -187,28 +184,8 @@ public class SysUitl {
public static void main(String[] args) throws UnknownHostException, SocketException {
//String ip = "192.068.0.103";
//System.out.println("===" + getMac(ip));
// TODO Auto-generated method stub
/* InetAddress ia=null;
try {
ia=ia.getLocalHost();
String localname=ia.getHostName();
String localip=ia.getHostAddress();
System.out.println("本机名称是:"+ localname);
System.out.println("本机的ip是 :"+localip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InetAddress ia1 = InetAddress.getLocalHost();//获取本地IP对象
try {
System.out.println("MAC ......... "+getMACAddress(ia1));
} catch (Exception e) {
e.printStackTrace();
}*/
System.out.println("MAC ......... "+getMACAddress());
String ip = "192.168.0.103";
System.out.println("===" + getkhdMac(ip));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment