- 浏览: 1011318 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 2195屏幕适配一直是一个让人头疼的问题,论坛上讨论这个问题的最后也 ... -
禁止Eclipse中xml文件Run as的XSL Transformation生成out.xml以方便Android应用开发
2012-08-26 21:38 2642可以在Eclipse里面配置,菜单Windows->P ... -
android 自带的主题 theme 的使用
2012-08-25 23:21 2373在android的sdk 安装目录data\r ... -
android开发之gallery 实现滚动一张且短距离滑动实现滚动
2011-12-19 18:50 1929首先gallery的特点就不用多说了吧,惯性滚动、半屏翻页,但 ... -
使用Jstat监控gc情况(收藏)
2011-12-19 13:22 1860性能测试过程中,我们 ... -
eclipse生成javadoc乱码解决
2011-10-24 09:37 1292eclipse在生成javadoc的时候出现乱码,是因为 ... -
java中在静态方法或变量中动态获取当前类的类名
2011-10-14 11:20 3703java中在静态方法中动态获取当前类的类名或者动态获取当前类的 ... -
飞鸽传书实现原理
2011-10-13 11:35 3261飞鸽传书的实现原理: (1)最关键的是局域网用户列表的 ... -
Android开发——利用Cursor+CursorAdapter实现界面实时更新(转)
2011-09-20 15:47 3085好久没有更新博客了 ... -
Nginx使用反向代理时 Hessian 的 411 错误解决方案【转】
2011-09-15 13:48 2363问题描述: 用 Hessian 实现 web se ... -
"Copy" did not complete normally. Please see the log for more information.
2011-05-06 17:19 4041在用android日志的时候老是弹出一个窗口,内容 ... -
jdk api下载地址备份
2011-02-15 10:58 1587中文jdk6的api: JDK6 API 中文版 H ... -
JAVA NIO 简介(转)
2010-12-09 13:03 1063http://www.iteye.com/topic/8344 ... -
netty的资料
2010-10-31 16:06 1291http://hornetq.sourceforge.net/ ... -
Java程序发邮件小例子(转载收藏)
2010-10-27 21:25 1562今天试了一个Java写的发邮件小例子,需要的jar包有 ... -
使用Netty 构造一个异步的httpclient
2010-09-21 00:35 7840原文地址:http://dev.firnow.com/co ... -
Netty使用初步
2010-09-21 00:26 13971收藏自:http://www.kafk ... -
集群环境下SESSION处理(转)
2010-09-08 15:24 1846本文转自:http://blog.csdn.net/l ... -
Java集合的Stack、Queue、Map的遍历
2010-09-08 13:00 1441在集合操作中,常常 ... -
<转>,防止刷新/后退引起的重复提交问题的Java Token代码,非Struts
2009-12-10 13:31 1918贴子转自http://hi.baidu.com/bobylou ...
相关推荐
在Java编程中,获取计算机硬件信息是常见的需求之一,其中之一就是获取网卡(Network Interface Card,简称NIC)的物理地址,也就是MAC地址。MAC地址是一个唯一标识网络接口的硬件地址,通常由六组两进制数字组成,...
JAVA 获取网卡物理地址(Windows 和 Linux) 在 Java 中获取网卡物理地址是一项常见的需求,特别是在开发网络相关的应用程序时。网卡物理地址,也称为 MAC 地址,是一个唯一的识别码,用来标识网络设备。今天,我们...
本文将深入解析在Java/JSP环境中获取客户端网卡MAC地址的三种常见方法,旨在为开发者提供全面而深入的理解。 ### 方法一:通过Java NIO(非阻塞I/O)库 Java NIO库提供了访问底层网络接口的能力,从而可以获取包括...
### Java 获取客户端 IP 和 MAC 地址 在Java Web开发中,有时我们需要获取客户端的IP地址甚至是MAC地址,以便进行安全验证、用户行为追踪等操作。本文将详细介绍如何通过Java来实现这一功能。 #### 一、获取客户端...
获取网卡MAC地址是网络管理、设备识别或者安全验证等场景中的常见需求。在不同的操作系统中,获取MAC地址的方法略有不同。以下是一些主要操作系统的获取方法: 1. **Windows系统**: - 命令行:通过运行`cmd`打开...
在对网内主机进行监控时需要通过java获取远程机器的mac地址
在Java编程中,获取服务器的IP地址和MAC地址是常见的需求,特别是在网络通信和系统管理中。本篇文章将详细介绍如何使用Java实现这一功能,包括针对单网卡和多网卡环境的情况。 首先,获取服务器的IP地址通常涉及到`...
在Java编程环境中,获取网络接口(网卡)的地址是一项常见的任务,特别是在系统级编程或者网络通信的应用中。本文将详细讲解如何利用J2SE(Java 2 Standard Edition)中的`ProcessBuilder`类来实现这一功能,特别是...
### Java 获取本机网卡的MAC地址 在Java开发中,有时我们需要获取当前计算机的MAC地址,例如在网络设备管理或安全认证等场景中。本文将详细介绍如何通过Java代码获取本机网卡的MAC地址,并针对不同的操作系统(如...
Java 中获取 IP 地址、主机名称、网卡地址 Java 中获取 IP 地址、主机名称、网卡地址是 NETWORK 编程中的一个重要主题。在 Java 中,我们可以使用 InetAddress 类和 Runtime 类来获取这些信息。下面我们来详细介绍...
java获取Centos7服务器网卡ip 子网掩码 默认网关 DNS 同时设置网卡 及 重启网卡参考
在Java编程语言中,获取计算机硬件的物理地址,即网卡MAC地址,是常见的系统信息获取需求。MAC地址是一个用于标识网络设备的唯一物理地址,通常由六组两字符的十六进制数字组成,例如“00:14:22:01:23:45”。本篇...
标题提到的“网卡MAC地址修改器”是一款软件工具,专为Windows操作系统设计,特别是针对Windows 10系统。它声称能够方便地修改网卡的MAC地址,并且在修改后无需重启计算机即可立即生效。这在传统的操作系统中通常...
本文将详细讲解如何在不同的操作系统中获取网卡的MAC地址。 ### Windows系统 在Windows中,可以通过命令行工具`cmd.exe`来获取MAC地址: 1. 打开命令提示符:按下`Win + R`,输入`cmd`,然后点击“确定”或按回车...
- **校验物理唯一性**:如果需要确保MAC地址在实际网络中是唯一的,可以查询网络接口或使用第三方库,如`java.net.NetworkInterface`类来获取和验证。 3. **MAC地址转换**: - **二进制与十六进制转换**:可以...
- **Java**:使用`java.net.NetworkInterface`类,遍历所有网络接口并获取MAC地址。 - **C#**:通过`ManagementClass`和`ManagementObjectCollection`操作WMI。 3. **第三方软件**:有些系统工具或网络诊断软件也...
在Linux和Windows环境下,获取本机所有网卡MAC地址的方法略有不同。在Linux中,可以通过`ifconfig`命令或`/sys/class/net`目录下的文件系统接口来获取;而在Windows中,可以使用WMI(Windows Management ...
- **Java**:使用`java.net.NetworkInterface`类,遍历所有网络接口并获取MAC地址。 3. 系统管理工具 大多数操作系统都提供了图形界面的网络设置工具,用户可以在其中查看设备的MAC地址: - **Windows**:控制...
Java提供了更直接的方式来获取MAC地址,主要通过`java.net.NetworkInterface`类。以下是一个简单的Java示例,展示了如何在Windows和Linux上获取MAC地址: ```java import java.net.NetworkInterface; import java...
这篇博客文章可能详细介绍了如何利用Jpcap库来获取网卡地址、数据源地址以及如何捕获和分析网络数据包。下面将对这些知识点进行深入探讨。 1. **网卡地址**: - 在计算机网络中,每个网卡都有一个唯一的物理地址,...