- 浏览: 548047 次
- 性别:
- 来自: 安徽
文章分类
最新评论
-
baynjh:
jp.ne.so_net.ga2.no_ji.jcom.JCo ...
java应用jcom将word转pdf -
zgw06629:
你好,请问你都做了哪些修改呢?是在客户端还是服务端?
http上传文件深度解析-高性能http传输 -
eidolon:
翻译有误。 l ?:意思是操作符左边的符号( ...
BNF 和EBNF的含义与用法(感谢译者:Sunnybill) -
huoyj:
请教一个问题,是不是HTTP请求里面没有包含上传文件在客户端的 ...
http上传文件深度解析-高性能http传输 -
a49688448:
“认清” 我还以为google怎么你了
最近终于认清了google
package com.etong.bms; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.util.StringTokenizer; import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException; public final class GetMacAddr { private final static String getMacAddress() throws IOException { String os = System.getProperty("os.name"); try { if (os.startsWith("Windows")) { return windowsParseMacAddress(windowsRunIpConfigCommand()); } else if (os.startsWith("Linux")) { return linuxParseMacAddress(linuxRunIfConfigCommand()); } else { throw new IOException("unknown operating system: " + os); } } catch (ParseException ex) { ex.printStackTrace(); throw new IOException(ex.getMessage()); } } /* * Linux stuff */ private final static String linuxParseMacAddress(String ipConfigResponse) throws ParseException { String localHost = null; try { localHost = InetAddress.getLocalHost().getHostAddress(); } catch (java.net.UnknownHostException ex) { ex.printStackTrace(); throw new ParseException(ex.getMessage(), 0); } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); boolean containsLocalHost = line.indexOf(localHost) >= 0; // see if line contains IP address if (containsLocalHost && lastMacAddress != null) { return lastMacAddress; } // see if line contains MAC address int macAddressPosition = line.indexOf("HWaddr"); if (macAddressPosition <= 0) continue; String macAddressCandidate = line.substring(macAddressPosition + 6) .trim(); if (linuxIsMacAddress(macAddressCandidate)) { lastMacAddress = macAddressCandidate; continue; } } ParseException ex = new ParseException("cannot read MAC address for " + localHost + " from [" + ipConfigResponse + "]", 0); ex.printStackTrace(); throw ex; } private final static boolean linuxIsMacAddress(String macAddressCandidate) { // TODO: use a smart regular expression if (macAddressCandidate.length() != 17) return false; return true; } private final static String linuxRunIfConfigCommand() throws IOException { Process p = Runtime.getRuntime().exec("ifconfig"); InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer = new StringBuffer(); for (;;) { int c = stdoutStream.read(); if (c == -1) break; buffer.append((char) c); } String outputText = buffer.toString(); stdoutStream.close(); return outputText; } /* * Windows stuff */ private final static String windowsParseMacAddress(String ipConfigResponse) throws ParseException { String localHost = null; try { localHost = InetAddress.getLocalHost().getHostAddress(); } catch (java.net.UnknownHostException ex) { ex.printStackTrace(); throw new ParseException(ex.getMessage(), 0); } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); // see if line contains IP address if (line.endsWith(localHost) && lastMacAddress != null) { return lastMacAddress; } // see if line contains MAC address int macAddressPosition = line.indexOf(":"); if (macAddressPosition <= 0) continue; String macAddressCandidate = line.substring(macAddressPosition + 1) .trim(); if (windowsIsMacAddress(macAddressCandidate)) { lastMacAddress = macAddressCandidate; continue; } } ParseException ex = new ParseException("cannot read MAC address from [" + ipConfigResponse + "]", 0); ex.printStackTrace(); throw ex; } private final static boolean windowsIsMacAddress(String macAddressCandidate) { // TODO: use a smart regular expression if (macAddressCandidate.length() != 17) return false; return true; } private final static String windowsRunIpConfigCommand() throws IOException { Process p = Runtime.getRuntime().exec("ipconfig /all"); InputStream stdoutStream = new BufferedInputStream(p.getInputStream()); StringBuffer buffer = new StringBuffer(); for (;;) { int c = stdoutStream.read(); if (c == -1) break; buffer.append((char) c); } String outputText = buffer.toString(); stdoutStream.close(); return outputText; } /* * Main */ public final static void main(String[] args) { try { System.out.println("Network infos"); System.out.println(" Operating System: " + System.getProperty("os.name")); System.out.println(" IP/Localhost: " + InetAddress.getLocalHost().getHostAddress()); System.out.println(" MAC Address: " + getMacAddress()); } catch (Throwable t) { t.printStackTrace(); } } }
发表评论
-
java获取项目路径
2010-12-16 13:40 1182在jsp和class文件中调用的相对路径不同。 在jsp里,根 ... -
CSS控制DIV圆角
2010-12-09 15:51 1879<!DOCTYPE HTML PUBLIC " ... -
强大的web打印功能
2010-08-24 11:17 11161.<html> 2.<head> ... -
一个java写的托盘练习
2010-08-14 15:48 977package minsize;import javax.sw ... -
Java的SystemTray类的使用方法
2010-08-14 15:38 3280Java的SystemTray类的使用方法 JDK1.6版增 ... -
Hibernate中发生"Session is closed" 的另一种可能!
2010-07-17 23:39 1720Hibernate中发生"Session ... -
求园柱体的表面积和体积
2010-06-13 11:50 32151.先创建一个Point类,然后定义Trianglele类。在 ... -
写一个Point类,计算两个Point实例之间的距离;写一个判断点是否在圆内的方法。
2010-06-13 11:47 7980写一个Point类,计算 ... -
打印分页代码
2009-10-27 15:27 1220<!-- define some variables u ... -
非常好的打印预览代码
2009-10-27 15:24 1907<!DOCTYPE html PUBLIC &quo ... -
http上传文件深度解析-高性能http传输
2009-10-24 16:59 11332http上传文件深度解析-高性能http传输 2008-12 ... -
使用java2word向已经建好的表格里插入数据
2009-05-18 13:41 2715上一篇讲如何NEW一个已经填充好数据的表格出来,这篇我介绍 ... -
使用java2word向word文档里插入文本、表格、图片
2009-05-18 13:41 5894import java.util.ArrayList; ... -
JSP request对象属性列表
2009-05-15 15:05 2990<% out.println("Protoc ... -
LDAP 集成应用实例
2009-05-15 13:58 9219我们部门有一个系统是专门用来记录大家的请假和加班的.这个系统有 ... -
IBM Portal与单点登录、集成企业级应用
2009-05-15 11:19 3432IBM Portal与单点登录、集 ... -
WAP 服务器设置
2009-04-11 15:53 1711WAP 服务器设置 二十一世纪是信息的世纪,以IP技 ... -
本地图片预览
2009-04-01 17:11 1162<?xml version="1.0" ... -
图片预装载技术
2009-04-01 17:08 1189<html> <body> < ... -
鼠标中键放大缩小图片
2009-04-01 17:03 1855<!DOCTYPE HTML PUBLIC " ...
相关推荐
执行main方法获取mac地址,最权威的demo自己测试已经正常使用。网上基本都是假的获取不到,只有我这个才是最方便的
获取客户端ip地址( 这个必须从客户端传到后台): jsp页面下,很简单,request....因为系统的VIew层是用JSF来实现的,因此页面上没法直接获得类似request,在bean里做了个强制转换java 获取客户端ip mac地址
在对网内主机进行监控时需要通过java获取远程机器的mac地址
java获取mac,通过命令获取裁剪后得到想要的内容
获取用户请求IP地址 根据IP地址获取mac地址
java中通过ip获取远程客户端的mac地址,支持跨平台
如何使用Java代码获取Android移动终端Mac地址.zip
java获取不同操作系统的名称以及mac地址工具类,例如:windows,Linux,Unix等
用java实现获取MAC地址的方法,用java实现获取MAC地址的方法
主要介绍了java编程实现获取机器IP地址及MAC地址的方法,实例分析了Java分别针对单网卡及多网卡的情况下获取服务器IP地址与MAC地址的相关技巧,需要的朋友可以参考下
获取计算机的mac地址和ip地址,mac地址返回的是一个list,ip地址是string
Java获取本机MAC地址IP地址主机名
Java内嵌Chrome浏览器,并实现web项目获取MAC地址,内含Ant打包代码,可以把程序打包到jar目录,直接用cmd文件运行
MAC地址合法性检测(C,C++, JAVA实现)
java 获取本机mac地址源码 计算机网络的实验内容
java获取本机网卡的MAC地址,/** * 测试用的main方法. * * @param argc * 运行参数. */ public static void main(String[] argc) { String os = getOSName(); System.out.println(os); if(os....
可以通过java获取客户端IPMAC主机名等信息。下载就能用,欢迎下载!
JAVA获取客户端MAC,web获取客户端MAC,Applet获取客户端MAC;JAVAweb开发;服务器端很难获取到客户端的MAC受路由器等....获取的到不正确或者被过滤掉;小弟,无奈写了一个客户端的Applet来获取客户端MAC然后再在传...
php与java获得电脑mac地址,根据不同系统获取,有window和linux