获取MAC地址和IP地址
来源:互联网 发布:淘宝pc宝贝链接转换 编辑:程序博客网 时间:2024/05/10 08:13
package pkg;
import java.io.*;
/**
* 获取MAC地址【转载】
*
*/
public class GetMac {
// 通过IP获取网卡地址
private 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;
}
// 通过机器名获取网卡地址
private 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) {
GetMac getmac;
getmac = new GetMac();
String mac = "";
mac = getmac.getMacAddressIP("192.168.0.100");// YOUR IP
System.out.println(mac);
mac = getmac.getMacAddressName("R61007");// YOUR HOST-NAME
System.out.println(mac);
}
}
获取ip地址的方法有二:
1.通过HttpServletRequest对象获取,可以在HttpServlet中获取,也可以在jsp中获取
a.在HttpServlet中获取
request.getRemoteAddr();
request.getRemoteHost();
b.在jsp中获取
在body中写下如下代码
<%
String a = request.getRemoteAddr();
String b = request.getRemoteHost();
String c = java.net.InetAddress.getLocalHost().getHostAddress();
%>
<script type="text/javascript">
var sys = ${it};
b = "<%=a%>";
</script>
2.不通过中间环节获取
String ip = java.net.InetAddress.getLocalHost().getHostAddress();
- 获取MAC地址和IP地址
- 获取IP地址和MAC地址
- android获取Mac地址和IP地址
- android获取Mac地址和IP地址
- Wince获取MAC地址和 ip地址
- js获取mac地址和ip地址
- java获取ip地址和Mac地址
- Android 获取Mac地址和IP地址
- 获取mac地址和IP地址方式
- 获取ip、mac、地址
- C# 获取局域网IP和MAC地址
- 获取机器IP和MAC地址
- C# 获取局域网IP和MAC地址
- jsp获取客户端ip和mac地址
- C# 获取IP和MAC地址
- c#获取本地IP和MAC地址
- c#获取本地IP和MAC地址
- c#获取本地IP和MAC地址
- mac 工具
- 面向站长和网站管理员的Web缓存加速指南[翻译]
- 如何架设svn服务器
- Linux--常用文件重定向命令
- Oracle 10G 如何使用超过1.7G的内存
- 获取MAC地址和IP地址
- DECLARE_DYNAMIC宏的添加
- SQL Server 2000 数据同步过程
- watchdog(看门狗)
- 数据结构学习记录连载5(堆栈的学习)
- SQL SERVER 2005 浏览多维数据集时出现"没有注册类别"错误
- cppodbc--c++的odbc封装类
- 初学汇编:MASMPlus下自定义Debug工具
- AT91SAM9263 WINCE 6.0 R2驱动开发-6X6矩阵键盘驱动