- 浏览: 995735 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (367)
- JavaScript (23)
- Java (60)
- Python (41)
- 其他 (36)
- SQL (4)
- 开发工具 (26)
- Linux (15)
- AJAX (6)
- Cache (3)
- 正则 (4)
- 架构 (9)
- 手机 (3)
- MySQL (4)
- Android (115)
- vps (1)
- 网站 (4)
- scale (3)
- 搜索引擎 (3)
- iPhone (2)
- hessian (1)
- hessdroid (1)
- 411 (1)
- jstat (1)
- gc (1)
- gallery (1)
- 惯性 (1)
- eclipse (1)
- mac wget error (1)
- miui file explorer 无用 解决办法 (1)
- vim (1)
最新评论
-
qingyezhangluo:
哎。楼主您既然是分享代码的为什么要加密的呢?而且问你密码还不回 ...
android应用换皮肤(转) -
MagicError:
kavoe 写道下载文件有密码。。。。
http抓包工具 -
knightdf:
我先试下再来
JAVA的RAS加密例子 -
kavoe:
下载文件有密码。。。。
http抓包工具 -
changanfounder:
hmc1985 写道setCallbackDuringFlin ...
android gallery滑动惯性问题
package test;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.StringTokenizer;
public final class NetworkUtils {
private final static int MACADDR_LENGTH = 17;
private final static String WIN_OSNAME = "Windows";
private final static String LINUX_OSNAME = "Linux";
private final static String OSX_OSNAME = "Mac OS X";
private final static String MACADDR_REG_EXP = "^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$";
private final static String WIN_MACADDR_EXEC = "ipconfig /all";
private final static String LINUX_MACADDR_EXEC = "ifconfig";
private final static String OSX_MACADDR_EXEC = "ifconfig";
public final static String getMacAddress() throws IOException{
String os = System.getProperty("os.name");
try{
if(os.startsWith(WIN_OSNAME)){
return windowsParseMacAddress(windowsIpConfigCommand());
}else if(os.startsWith(LINUX_OSNAME)){
return linuxParseMacAddress(linuxRunIfConfigCommand());
}else if(os.startsWith(OSX_OSNAME)) {
return osxParseMacAddress(osxRunIfConfigCommand());
}else{
throw new IOException("OS not supported : " + os);
}
}catch(Exception e){
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
/**
* OSX stuff
*/
private final static String osxParseMacAddress(String ipConfigOutput) 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(ipConfigOutput, "\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("ether");
if(macAddressPosition != 0) {
continue;
}
String macAddressCandidate = line.substring(macAddressPosition + 6).trim();
if(osxIsMacAddress(macAddressCandidate)) {
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException
("cannot read MAC address for " + localHost + " from [" + ipConfigOutput + "]", 0);
ex.printStackTrace();
throw ex;
}
private final static boolean osxIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String osxRunIfConfigCommand() throws IOException{
Process p = Runtime.getRuntime().exec(OSX_MACADDR_EXEC);
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;
}
/**
* Linux stuff
*/
private final static String linuxParseMacAddress(String ipConfigOutput) throws ParseException{
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ParseException(e.getMessage(),0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigOutput,"\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 [" + ipConfigOutput + "]",0);
ex.printStackTrace();
throw ex;
}
private final static boolean linuxIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String linuxRunIfConfigCommand() throws IOException{
Process p = Runtime.getRuntime().exec(LINUX_MACADDR_EXEC);
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 ipConfigOutput) throws ParseException{
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ParseException(e.getMessage(),0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigOutput,"\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 [" + ipConfigOutput + "]",0);
ex.printStackTrace();
throw ex;
}
private final static boolean windowsIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String windowsIpConfigCommand() throws IOException {
Process p = Runtime.getRuntime().exec(WIN_MACADDR_EXEC);
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;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
System.out.println(" MAC ADDRESS");
System.out.println(" OS :" + System.getProperty("os.name"));
System.out.println(" IP/Localhost : " + InetAddress.getLocalHost().getHostAddress());
System.out.println(" MAC Address : " + getMacAddress());
}catch(Throwable t){
t.printStackTrace();
}
}
}
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.StringTokenizer;
public final class NetworkUtils {
private final static int MACADDR_LENGTH = 17;
private final static String WIN_OSNAME = "Windows";
private final static String LINUX_OSNAME = "Linux";
private final static String OSX_OSNAME = "Mac OS X";
private final static String MACADDR_REG_EXP = "^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$";
private final static String WIN_MACADDR_EXEC = "ipconfig /all";
private final static String LINUX_MACADDR_EXEC = "ifconfig";
private final static String OSX_MACADDR_EXEC = "ifconfig";
public final static String getMacAddress() throws IOException{
String os = System.getProperty("os.name");
try{
if(os.startsWith(WIN_OSNAME)){
return windowsParseMacAddress(windowsIpConfigCommand());
}else if(os.startsWith(LINUX_OSNAME)){
return linuxParseMacAddress(linuxRunIfConfigCommand());
}else if(os.startsWith(OSX_OSNAME)) {
return osxParseMacAddress(osxRunIfConfigCommand());
}else{
throw new IOException("OS not supported : " + os);
}
}catch(Exception e){
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
/**
* OSX stuff
*/
private final static String osxParseMacAddress(String ipConfigOutput) 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(ipConfigOutput, "\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("ether");
if(macAddressPosition != 0) {
continue;
}
String macAddressCandidate = line.substring(macAddressPosition + 6).trim();
if(osxIsMacAddress(macAddressCandidate)) {
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException
("cannot read MAC address for " + localHost + " from [" + ipConfigOutput + "]", 0);
ex.printStackTrace();
throw ex;
}
private final static boolean osxIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String osxRunIfConfigCommand() throws IOException{
Process p = Runtime.getRuntime().exec(OSX_MACADDR_EXEC);
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;
}
/**
* Linux stuff
*/
private final static String linuxParseMacAddress(String ipConfigOutput) throws ParseException{
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ParseException(e.getMessage(),0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigOutput,"\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 [" + ipConfigOutput + "]",0);
ex.printStackTrace();
throw ex;
}
private final static boolean linuxIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String linuxRunIfConfigCommand() throws IOException{
Process p = Runtime.getRuntime().exec(LINUX_MACADDR_EXEC);
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 ipConfigOutput) throws ParseException{
String localHost = null;
try {
localHost = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ParseException(e.getMessage(),0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigOutput,"\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 [" + ipConfigOutput + "]",0);
ex.printStackTrace();
throw ex;
}
private final static boolean windowsIsMacAddress(String macAddressCandidate){
if(macAddressCandidate.length() != MACADDR_LENGTH){
return false;
}
if(!macAddressCandidate.matches(MACADDR_REG_EXP)){
return false;
}
return true;
}
private final static String windowsIpConfigCommand() throws IOException {
Process p = Runtime.getRuntime().exec(WIN_MACADDR_EXEC);
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;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
System.out.println(" MAC ADDRESS");
System.out.println(" OS :" + System.getProperty("os.name"));
System.out.println(" IP/Localhost : " + InetAddress.getLocalHost().getHostAddress());
System.out.println(" MAC Address : " + getMacAddress());
}catch(Throwable t){
t.printStackTrace();
}
}
}
发表评论
-
android屏幕适配
2012-11-16 17:24 2140屏幕适配一直是一个让人头疼的问题,论坛上讨论这个问题的最后也 ... -
禁止Eclipse中xml文件Run as的XSL Transformation生成out.xml以方便Android应用开发
2012-08-26 21:38 2585可以在Eclipse里面配置,菜单Windows->P ... -
android 自带的主题 theme 的使用
2012-08-25 23:21 2330在android的sdk 安装目录data\r ... -
android开发之gallery 实现滚动一张且短距离滑动实现滚动
2011-12-19 18:50 1882首先gallery的特点就不用多说了吧,惯性滚动、半屏翻页,但 ... -
使用Jstat监控gc情况(收藏)
2011-12-19 13:22 1802性能测试过程中,我们 ... -
eclipse生成javadoc乱码解决
2011-10-24 09:37 1233eclipse在生成javadoc的时候出现乱码,是因为 ... -
java中在静态方法或变量中动态获取当前类的类名
2011-10-14 11:20 3646java中在静态方法中动态获取当前类的类名或者动态获取当前类的 ... -
飞鸽传书实现原理
2011-10-13 11:35 3120飞鸽传书的实现原理: (1)最关键的是局域网用户列表的 ... -
Android开发——利用Cursor+CursorAdapter实现界面实时更新(转)
2011-09-20 15:47 3037好久没有更新博客了 ... -
Nginx使用反向代理时 Hessian 的 411 错误解决方案【转】
2011-09-15 13:48 2326问题描述: 用 Hessian 实现 web se ... -
"Copy" did not complete normally. Please see the log for more information.
2011-05-06 17:19 4002在用android日志的时候老是弹出一个窗口,内容 ... -
jdk api下载地址备份
2011-02-15 10:58 1536中文jdk6的api: JDK6 API 中文版 H ... -
JAVA NIO 简介(转)
2010-12-09 13:03 1019http://www.iteye.com/topic/8344 ... -
netty的资料
2010-10-31 16:06 1253http://hornetq.sourceforge.net/ ... -
Java程序发邮件小例子(转载收藏)
2010-10-27 21:25 1531今天试了一个Java写的发邮件小例子,需要的jar包有 ... -
使用Netty 构造一个异步的httpclient
2010-09-21 00:35 7800原文地址:http://dev.firnow.com/co ... -
Netty使用初步
2010-09-21 00:26 13859收藏自:http://www.kafk ... -
集群环境下SESSION处理(转)
2010-09-08 15:24 1806本文转自:http://blog.csdn.net/l ... -
Java集合的Stack、Queue、Map的遍历
2010-09-08 13:00 1388在集合操作中,常常 ... -
<转>,防止刷新/后退引起的重复提交问题的Java Token代码,非Struts
2009-12-10 13:31 1873贴子转自http://hi.baidu.com/bobylou ...
相关推荐
刚刚发了一个获取电脑硬盘序列号的demo 想想还是把这个获取MAC地址的也发上来吧 请大家指点一二
在对网内主机进行监控时需要通过java获取远程机器的mac地址
java获取本机网卡的MAC地址,/** * 测试用的main方法. * * @param argc * 运行参数. */ public static void main(String[] argc) { String os = getOSName(); System.out.println(os); if(os....
主要介绍了java编程实现获取机器IP地址及MAC地址的方法,实例分析了Java分别针对单网卡及多网卡的情况下获取服务器IP地址与MAC地址的相关技巧,需要的朋友可以参考下
Java/JSP获得客户端网卡MAC地址的三种方法解析
java获取Centos7服务器网卡ip 子网掩码 默认网关 DNS 同时设置网卡 及 重启网卡参考
网卡mac地址修改器 真正支持win10 不需重启即时生效 支持win7 8 10 网卡mac地址修改器 真正支持win10 不需重启即时生效 支持win7 8 10
//Java获得CPU序列号和网卡Mac地址 /* 利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,...
NULL 博文链接:https://hylong05.iteye.com/blog/560600
很容易的就可以获得机器的MAC(网卡)地址,是用java语言编写的
java 程序, 亲测。 获取计算机的网卡IP地址。 runttime 的调用。
允许这个测试类,就可以轻松的获取到本地连接的mac网卡地址了,就可以作为设备的唯一编码。
C#程序源码,自己写的小工具,用于获取本机Mac地址,并对Mac地址进行AES加密及解密,已经过测试,方便使用。
java代码随机生成 00:18:34:6A:B2:67
很容易就可以获得 机器的MAC地址,我这使用java编写的。
从一个txt文件中导入一个网段内的计算机的名字,IP,MAC地址(这些是通过别的软件扫描出来的,我不懂做),然后再填写别的一些配置,就生成一个xml配置文件。客户端运行后会先读取本机的MAC地址,再根据该xml文件...
java.io.FileInputStream fis = new java.io.FileInputStream( new java.io.File("d:\\数据库.zip")); // 转换成网络输出流 java.net.ServerSocket ss = new java.net.ServerSocket(9000); java.net....
网上搜集了获取IP、MAC方法做了总结,提供多种获取IP、mac方式。支持获取多网卡IP、MAc获取
8.java简单的获取系统网卡mac地址 5 9. 增加tomcat的内存 6 10.JAVA获取系统当前的用户 7 11.javascript获取客户端网卡MAC地址和IP地址和计算机名 7 12.JAVA反射 8 13. 自定义ClassLoader 13 14. double保留两位数的...
Wifi连接网络,通过程序你将了解到定义WifiManager对象,定义WifiInfo对象,获取网络连接列表,定义一个WifiLock,打开Wifi网卡,关闭Wifi网卡,检查当前Wifi网卡状态,扫描周边网络,每次点击扫描之前清空上一次的...