java获取服务器端网卡地址
2011-03-03 15:59
363 查看
package com.ctgusec.bean;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
/**
*
* @author zhupan
* @version 1.0
*/
public class MACAddress {
public MACAddress() {
}
public static String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
System.out.println(address);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {
}
}
return address;
}
// 通过IP获取网卡地址
public static String getMacAddressIP(String remotePcIP) {
String str = "";
String macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -A " + remotePcIP);
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) {
macAddress = str.substring(
str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException ex) {
}
return macAddress;
}
// 通过机器名获取网卡地址
public static String getMacAddressName(String remotePcIP) {
String str = "";
String macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -a " + remotePcIP);
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) {
macAddress = str.substring(
str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException ex) {
}
return macAddress;
}
public static void main(String[] args) {
System.out.println(MACAddress.getMACAddress());
System.out.println(getMacAddressIP("192.168.175.200"));
System.out.println(getMacAddressName("527fefbedd5b43b."));
}
}
package com.ctgusec.bean;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
/**
*
* @author zhupan
* @version 1.0
*/
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.175.66"));
try {
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address=" + procAll(netdata));
} catch (IOException e) {
System.out.println("error=" + e);
}
}
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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
/**
*
* @author zhupan
* @version 1.0
*/
public class MACAddress {
public MACAddress() {
}
public static String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
System.out.println(address);
break;
}
}
br.close();
return address.trim();
} catch (IOException e) {
}
}
return address;
}
// 通过IP获取网卡地址
public static String getMacAddressIP(String remotePcIP) {
String str = "";
String macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -A " + remotePcIP);
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) {
macAddress = str.substring(
str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException ex) {
}
return macAddress;
}
// 通过机器名获取网卡地址
public static String getMacAddressName(String remotePcIP) {
String str = "";
String macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -a " + remotePcIP);
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) {
macAddress = str.substring(
str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException ex) {
}
return macAddress;
}
public static void main(String[] args) {
System.out.println(MACAddress.getMACAddress());
System.out.println(getMacAddressIP("192.168.175.200"));
System.out.println(getMacAddressName("527fefbedd5b43b."));
}
}
package com.ctgusec.bean;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
/**
*
* @author zhupan
* @version 1.0
*/
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.175.66"));
try {
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address=" + procAll(netdata));
} catch (IOException e) {
System.out.println("error=" + e);
}
}
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获取服务器端网卡地址
- java获取服务器端网卡地址
- Java获取网卡的mac地址
- java获取本机网卡的MAC地址
- java如何获取网卡地址(硬件地址)
- java执行系统命令,获取网卡物理地址
- java程序获取网卡地址
- php获取服务器端机器网卡的物理(MAC)地址
- java服务器端根据ip获取客户端mac地址
- Java获取CPU序列号和网卡Mac地址
- java获取当前操作系统名称以及各系统的本机网卡地址
- java简单的获取windows系统网卡mac地址
- OSMacTool java获取本机mac地址(网卡地址)
- java简单的获取windows系统网卡mac地址
- java获取本机网卡的MAC地址
- 利用Java获取本机网卡的MAC地址
- 新浪旧事-JAVA之获取网卡物理地址
- PL/SQL调用JAVA获取网卡MAC地址
- JAVA服务器端获取客户端远程地址,根据IP获取远程地址,各IP地址查询接口比较
- java,jsp获取客户端网卡物理地址