JAVA MacUtil
来源:互联网 发布:c语言编程简易小游戏 编辑:程序博客网 时间:2024/05/29 14:10
package reflect;import java.io.IOException;import java.io.InputStreamReader;import java.io.LineNumberReader;public class MacUtil {public String getMACAddress2(String ip){ String str = ""; String macAddress = ""; try { Process pp = Runtime.getRuntime().exec("ping " + ip); Process p = Runtime.getRuntime().exec("arp -a"); InputStreamReader ir = new InputStreamReader(p.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf(ip) > 1) { macAddress = str.substring(str.indexOf(ip) + 22, 41).toUpperCase(); if("00-00-00-00-00-00".equals(macAddress)){ macAddress = null; } ir.close(); input.close(); break; } } } } catch (IOException e) { e.printStackTrace(System.out); } return macAddress; }public String getMACAddress(String ip){ String str = ""; String macAddress = ""; try { Process p = Runtime.getRuntime().exec("nbtstat -A " + ip); InputStreamReader ir = new InputStreamReader(p.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf("MAC Address") > 1) { macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length()); ir.close(); input.close(); break; } } } } catch (IOException e) { e.printStackTrace(System.out); } if(macAddress==null || "".equals(macAddress)){ macAddress = this.getMACAddress2(ip); } return macAddress; }public static void main(String[] args) {MacUtil m = new MacUtil();System.out.println(m.getMACAddress("192.168.0.123"));}}
0 0
- JAVA MacUtil
- Java MacUtil 获取mac地址 工具类
- java
- JAVA
- JAVA
- JAVA
- java
- Java
- Java
- JAVA:
- java
- java
- java
- java
- Java
- java
- java
- java
- 未受信任的发布者
- run命令 快捷
- 苹果开发 笔记(28)
- 经典的机器学习方面源代码库
- 路径下获取文件(类似安卓指定路径文件获取)
- JAVA MacUtil
- Scrum
- 新人对于java异常的理解
- HD—OJ——吃糖果
- Ruby Array and .max
- 学习ASP.NET MVC5框架揭秘笔记-ASP.NET路由(六)
- Borg论文(Larmport版)
- Java回忆录(七)-------面向对象-----进阶篇
- 确定主机字节序的程序