From 66035957ea76de2e1623d2e9a6c7ce3af8df3917 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Fri, 8 Dec 2017 11:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E5=8F=AB=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lyms/hospitalapi/whfy/VirtualCallService.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/hospitalapi/whfy/VirtualCallService.java b/platform-operate-api/src/main/java/com/lyms/hospitalapi/whfy/VirtualCallService.java index 315b591..5820e08 100644 --- a/platform-operate-api/src/main/java/com/lyms/hospitalapi/whfy/VirtualCallService.java +++ b/platform-operate-api/src/main/java/com/lyms/hospitalapi/whfy/VirtualCallService.java @@ -392,19 +392,17 @@ public class VirtualCallService { return macAddress; } - //获取非本地IP的MAC地址 - Process p = Runtime.getRuntime().exec("arp " + ip); - InputStreamReader isr = new InputStreamReader(p.getInputStream()); - BufferedReader br = new BufferedReader(isr); - while ((line = br.readLine()) != null) { - if (line != null) { - int index = line.indexOf(MAC_ADDRESS_PREFIX); - if (index != -1) { - macAddress = line.substring(index + MAC_ADDRESS_PREFIX.length()).trim().toUpperCase(); - } - } + Process process = Runtime.getRuntime().exec("arp "+ip); + InputStreamReader ir = new InputStreamReader(process.getInputStream()); + LineNumberReader input = new LineNumberReader(ir); + StringBuffer s = new StringBuffer(); + while ((line = input.readLine()) != null) { + s.append(line); + } + macAddress = s.toString(); + if (macAddress != null) { + macAddress = macAddress.substring(macAddress.indexOf(":") - 2, macAddress.lastIndexOf(":") + 3); } - br.close(); } catch (IOException e) { e.printStackTrace(System.out); } -- 1.8.3.1