java jsp 获取电脑MAC地址
2013-06-28 23:45
260 查看
package filters;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class GetMACAddress {
public String getMACAddress(String ipAddress) {
String str = "", strMAC = "", macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.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) {
strMAC = str.substring(str.indexOf("MAC Address") + 14,
str.length());
break;
}
}
}
} catch (IOException ex) {
return "Can't Get MAC Address!";
}
//
if (strMAC.length() < 17) {
return "Error!";
}
macAddress = strMAC.substring(0, 2) + ":" + strMAC.substring(3, 5)
+ ":" + strMAC.substring(6, 8) + ":" + strMAC.substring(9, 11)
+ ":" + strMAC.substring(12, 14) + ":"
+ strMAC.substring(15, 17);
//
return macAddress;
}
public static void main(String[] args) {
GetMACAddress getMACAddress = new GetMACAddress();
System.out.println(getMACAddress.getMACAddress("192.168.0.100")); // 获得该ip地址的mac地址
}
public static String procAll(String str) {
return procStringEnd(procFirstMac(procAddress(str)));
}
public static String procAddress(String str) {
int indexof = str.indexOf("Physical Address");
if (indexof > 0) {
return str.substring(indexof, str.length());
}
return str;
}
public static String procFirstMac(String str) {
int indexof = str.indexOf(":");
if (indexof > 0) {
return str.substring(indexof + 1, str.length()).trim();
}
return str;
}
public static String procStringEnd(String str) {
int indexof = str.indexOf("\r");
if (indexof > 0) {
return str.substring(0, indexof).trim();
}
return str;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class GetMACAddress {
public String getMACAddress(String ipAddress) {
String str = "", strMAC = "", macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.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) {
strMAC = str.substring(str.indexOf("MAC Address") + 14,
str.length());
break;
}
}
}
} catch (IOException ex) {
return "Can't Get MAC Address!";
}
//
if (strMAC.length() < 17) {
return "Error!";
}
macAddress = strMAC.substring(0, 2) + ":" + strMAC.substring(3, 5)
+ ":" + strMAC.substring(6, 8) + ":" + strMAC.substring(9, 11)
+ ":" + strMAC.substring(12, 14) + ":"
+ strMAC.substring(15, 17);
//
return macAddress;
}
public static void main(String[] args) {
GetMACAddress getMACAddress = new GetMACAddress();
System.out.println(getMACAddress.getMACAddress("192.168.0.100")); // 获得该ip地址的mac地址
}
public static String procAll(String str) {
return procStringEnd(procFirstMac(procAddress(str)));
}
public static String procAddress(String str) {
int indexof = str.indexOf("Physical Address");
if (indexof > 0) {
return str.substring(indexof, str.length());
}
return str;
}
public static String procFirstMac(String str) {
int indexof = str.indexOf(":");
if (indexof > 0) {
return str.substring(indexof + 1, str.length()).trim();
}
return str;
}
public static String procStringEnd(String str) {
int indexof = str.indexOf("\r");
if (indexof > 0) {
return str.substring(0, indexof).trim();
}
return str;
}
}
相关文章推荐
- java工具类,在Windows,Linux系统获取电脑的MAC地址、本地IP、电脑名
- JAVA,JSP,Servlet获取当前工程路径-绝对路径
- Java语言 > JSP教程 > JSP远程获取图像的大小
- java通过ip获取网卡MAC地址
- JAVA获取客户端请求电脑IP,操作系统等等各种信息
- Java从服务器上获取时间动态显示在jsp页面实现思路
- Java获取客户端请求电脑IP,操作系统等等各种信息
- java/jsp获取当前时间是本年的第几周
- JAVA,JSP,Servlet获取当前工程路径-绝对路径
- java/jsp获取当前路径的几种方法
- java 小记:获取 jsp 页面参数发现中文乱码
- Java 程序获取系统硬件信息之网卡MAC地址
- java(JSP)中几种获取项目路径方式
- Java获取mac地址的方法
- [java] Servlet/jsp 中 获取页面所有传递参数
- js如何获取jsp页面中嵌入的java代码中的变量?
- JAVA/JSP/Servlet获取当前工程路径-绝对路径
- 用js获取jsp的java变量值
- java后台jsp Request获取url信息的各种方法比较