根据IP地址获取用户的MAC地址
来源:互联网 发布:禅道的数据库配置 编辑:程序博客网 时间:2024/06/06 14:16
/** * 根据IP地址获取mac地址 * @param ipAddress 127.0.0.1 * @return * @throws SocketException * @throws UnknownHostException */public static String getLocalMac(String ipAddress) throws SocketException,UnknownHostException {// TODO Auto-generated method stubString str = "";String macAddress = "";final String LOOPBACK_ADDRESS = "127.0.0.1";// 如果为127.0.0.1,则获取本地MAC地址。if (LOOPBACK_ADDRESS.equals(ipAddress)) {InetAddress inetAddress = InetAddress.getLocalHost();// 貌似此方法需要JDK1.6。byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();// 下面代码是把mac地址拼装成StringStringBuilder sb = new StringBuilder();for (int i = 0; i < mac.length; i++) {if (i != 0) {sb.append("-");}// mac[i] & 0xFF 是为了把byte转化为正整数String s = Integer.toHexString(mac[i] & 0xFF);sb.append(s.length() == 1 ? 0 + s : s);}// 把字符串所有小写字母改为大写成为正规的mac地址并返回macAddress = sb.toString().trim().toUpperCase();return macAddress;} else {// 获取非本地IP的MAC地址try {System.out.println(ipAddress);Process p = Runtime.getRuntime().exec("nbtstat -A " + ipAddress);System.out.println("===process=="+p);InputStreamReader ir = new InputStreamReader(p.getInputStream());BufferedReader br = new BufferedReader(ir);while ((str = br.readLine()) != null) {if(str.indexOf("MAC")>1){macAddress = str.substring(str.indexOf("MAC")+9, str.length());macAddress = macAddress.trim();System.out.println("macAddress:" + macAddress);break;}}p.destroy();br.close();ir.close();} catch (IOException ex) {}return macAddress;}}
阅读全文
0 0
- 根据IP地址获取用户的MAC地址
- 根据用户IP获取用户的地址。
- 根据IP地址获取用户的MAC地址Java代码(未测试)
- 根据Ip地址 获取 mac地址
- 根据IP地址获取MAC地址
- 根据IP地址获取对应的MAC地址
- java web根据访问的ip地址获取MAC地址
- 根据IP获取对象mac地址。
- 根据HttpServletRequest获取用户真实IP地址
- 根据HttpServletRequest获取用户真实IP地址
- 根据HttpServletRequest获取用户真实IP地址
- js根据ip地址获取用户地点的接口使用方法
- 获取指定IP地址的MAC地址
- java获取登陆用户ip和mac地址的方法
- 根据IP获取地址
- 根据ip获取地址
- 根据ip获取地址
- 根据IP获取地址
- cocos2d-x 3.10 开发环境搭建及VS安装各种坑
- Java基础篇《1》--数据类型
- 在tp中数据去重并获取自定义字段
- 初2019级编程社团期末考试(20170610)-第一题解题报告
- linux下docker安装与使用 1
- 根据IP地址获取用户的MAC地址
- java数据库工具类
- python学习之if __name__ == 'main': 的作用和原理
- java多线程之生产者与消费者案例
- 九度1026:又一版 A+B
- Android使用FFmpeg 解码H264并播放(二)
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- Smalidea+IntelliJ IDEA/Android Studio动态调试安卓app教程
- Android 自定义ViewGroup 实战篇 -> 实现FlowLayout