- 浏览: 2969372 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (893)
- android (110)
- iphone (198)
- java (79)
- JavaScript手册-目录 (9)
- JavaScript手册-Array (19)
- JavaScript手册-Boolean (5)
- JavaScript手册-Date (50)
- JavaScript手册-Math (30)
- JavaScript手册-Number (14)
- JavaScript手册-RegExp (7)
- JavaScript手册-String (38)
- JavaScript手册-全局函数 (8)
- JavaScript实用脚本 (7)
- Others (21)
- java-jpcap (7)
- java-thread (1)
- ibm文章 (3)
- classloader (2)
- java-filter (2)
- 运行环境 (33)
- java-正则 (2)
- oracle (1)
- linux-shell (26)
- wap (1)
- sqlite (3)
- wow (1)
- jvm (1)
- git (5)
- unity3d (29)
- iap (2)
- mysql (23)
- nginx (14)
- tomcat (9)
- apache (2)
- php (1)
- ubuntu (40)
- rsa (1)
- golang (21)
- appstore (5)
- sftp (2)
- log4j (2)
- netty (18)
- 测试工具 (6)
- memcache (5)
- 设计模式 (1)
- centos (8)
- google_iab (5)
- iOS专题 (4)
- mac (10)
- 安装配置帮助手册 (2)
- im4java_graphicsmagick (5)
- inotify-tools (1)
- erlang (6)
- 微信支付 (1)
- redis (8)
- RabbitMQ (5)
最新评论
-
heng123:
Netty视频教程https://www.douban.com ...
netty4.0.23 初学的demo -
maotou1988:
使用Netty进行Android与Server端通信实现文字发 ...
netty4.0.23 初学的demo -
码革裹尸:
非常感谢,正好用上
android 呼入电话的监听(来电监听) -
rigou:
提示的/222.177.4.242 无法链接到ip地址,是什 ...
通过 itms:services://? 在线安装ipa ,跨过app-store -
duwanbo:
GridView与数据绑定
★★★ 本篇为原创,需要引用转载的朋友请注明:《 http://stephen830.iteye.com/blog/255210 》 谢谢支持! ★★★
软件项目或者产品有时候会用到本机网卡的物理MAC地址,例如结合MAC地址进行登录验证等等,当然这种项目一般在局域网内运行,能相对提高系统的安全性。
下面列出了java读取MAC地址的工具方法,可以读取windows和非windows操作系统(linux,unix)下的MAC地址。如果你的操作系统很特殊的话,可以对方法进行扩充,原理类似的。
分享知识,分享快乐,希望文章能给需要的朋友带来小小的帮助。
不错,不错,,支持楼主
软件项目或者产品有时候会用到本机网卡的物理MAC地址,例如结合MAC地址进行登录验证等等,当然这种项目一般在局域网内运行,能相对提高系统的安全性。
下面列出了java读取MAC地址的工具方法,可以读取windows和非windows操作系统(linux,unix)下的MAC地址。如果你的操作系统很特殊的话,可以对方法进行扩充,原理类似的。
/* * Created on 2005-6-5 * Author stephen * Email zhoujianqiang AT gmail DOT com * CopyRight(C)2005-2008 , All rights reserved. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * 与系统相关的一些常用工具方法. * * @author stephen * @version 1.0.0 */ public class SystemTool { /** * 获取当前操作系统名称. * return 操作系统名称 例如:windows xp,linux 等. */ public static String getOSName() { return System.getProperty("os.name").toLowerCase(); } /** * 获取unix网卡的mac地址. * 非windows的系统默认调用本方法获取.如果有特殊系统请继续扩充新的取mac地址方法. * @return mac地址 */ public static String getUnixMACAddress() { String mac = null; BufferedReader bufferedReader = null; Process process = null; try { process = Runtime.getRuntime().exec("ifconfig eth0");// linux下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息 bufferedReader = new BufferedReader(new InputStreamReader(process .getInputStream())); String line = null; int index = -1; while ((line = bufferedReader.readLine()) != null) { index = line.toLowerCase().indexOf("hwaddr");// 寻找标示字符串[hwaddr] if (index >= 0) {// 找到了 mac = line.substring(index +"hwaddr".length()+ 1).trim();// 取出mac地址并去除2边空格 break; } } } catch (IOException e) { e.printStackTrace(); } finally { try { if (bufferedReader != null) { bufferedReader.close(); } } catch (IOException e1) { e1.printStackTrace(); } bufferedReader = null; process = null; } return mac; } /** * 获取widnows网卡的mac地址. * @return mac地址 */ public static String getWindowsMACAddress() { String mac = null; BufferedReader bufferedReader = null; Process process = null; try { process = Runtime.getRuntime().exec("ipconfig /all");// windows下的命令,显示信息中包含有mac地址信息 bufferedReader = new BufferedReader(new InputStreamReader(process .getInputStream())); String line = null; int index = -1; while ((line = bufferedReader.readLine()) != null) { index = line.toLowerCase().indexOf("physical address");// 寻找标示字符串[physical address] if (index >= 0) {// 找到了 index = line.indexOf(":");// 寻找":"的位置 if (index>=0) { mac = line.substring(index + 1).trim();// 取出mac地址并去除2边空格 } break; } } } catch (IOException e) { e.printStackTrace(); } finally { try { if (bufferedReader != null) { bufferedReader.close(); } } catch (IOException e1) { e1.printStackTrace(); } bufferedReader = null; process = null; } return mac; } /** * 测试用的main方法. * * @param argc * 运行参数. */ public static void main(String[] argc) { String os = getOSName(); System.out.println(os); if(os.startsWith("windows")){ //本地是windows String mac = getWindowsMACAddress(); System.out.println(mac); }else{ //本地是非windows系统 一般就是unix String mac = getUnixMACAddress(); System.out.println(mac); } } }
分享知识,分享快乐,希望文章能给需要的朋友带来小小的帮助。
评论
12 楼
feng5199
2011-11-11
Windows7获取的是乱码,没法查找
11 楼
FlashHorse
2011-11-10
楼主 window 7貌似不行呀
10 楼
菜菜天堂
2009-10-10
机器上安装了VMware的虚拟机,使用ipconfig /all 指令会显示好几个,最好加上个判断是否是本地连接的语句。
就像下面实际的是00-03-53-77-E1-32,而程序遇到虚拟机的00-50-56-C0-00-08就算获取到了。。
Windows IP Configuration
Host Name . . . . . . . . . . . . : www-yokli-test
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.184.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.81.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . : eddd.com.cn
Description . . . . . . . . . . . : Broadcom NetLink (TM) Gigabit Ethern
et
Physical Address. . . . . . . . . : 00-03-53-77-E1-32
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.42.41
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.42.254
DHCP Server . . . . . . . . . . . : 192.168.42.254
就像下面实际的是00-03-53-77-E1-32,而程序遇到虚拟机的00-50-56-C0-00-08就算获取到了。。
Windows IP Configuration
Host Name . . . . . . . . . . . . : www-yokli-test
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.184.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.81.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . : eddd.com.cn
Description . . . . . . . . . . . : Broadcom NetLink (TM) Gigabit Ethern
et
Physical Address. . . . . . . . . : 00-03-53-77-E1-32
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.42.41
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.42.254
DHCP Server . . . . . . . . . . . : 192.168.42.254
9 楼
ivyloo
2009-06-01
很有用,谢谢了!
8 楼
netstorm
2009-03-31
搞成数组返回合适点, 特别是笔记本肯定是2个网卡了
另外最好取已连接网卡的物理地址, 比如像我现在是网线连接的,却取了个无线网卡的mac
另外最好取已连接网卡的物理地址, 比如像我现在是网线连接的,却取了个无线网卡的mac
7 楼
mum0532javaeye
2009-03-31
论坛的回复机制很垃圾,很浪费别人的宝贵时间。
楼主的帖子很有意义,收藏了
楼主的帖子很有意义,收藏了
6 楼
oldman
2009-02-27
呵呵,很有意思。
5 楼
rich130
2009-02-22
学到知道精通为止
4 楼
danjingwu
2008-10-31
不错,学习
3 楼
stephen830
2008-10-30
daiwenting2601 写道
不错,不错,,支持楼主
2 楼
daiwenting2601
2008-10-30
不错,不错,,支持楼主
1 楼
srdrm
2008-10-20
这招牛,呵呵
发表评论
-
Java的内存机制
2016-08-22 13:27 4501.Java的内存机制 Java 把内存划分成两 ... -
监听域对象中属性的变更的监听器
2016-07-18 19:06 1704监听域对象中属性的变更的监听器 域对象中属性 ... -
HttpSessionActivationListener
2016-07-18 18:46 605HttpSessionActivationListe ... -
Web容器监听器(实现在线统计人数,踢人)
2016-07-18 10:48 913Web容器监听器(实现在线统计人数,踢人) Servl ... -
HttpSessionBindingListener接口
2016-07-18 10:29 605HttpSessionBindingListene ... -
ServletRequestAttributeListener接口
2016-07-17 22:24 7932. HttpSessionAttribut ... -
Servlet3中异步Servlet特性介绍
2016-07-17 15:50 805Servlet3中异步Servlet特性介绍 ... -
HttpSessionAttributeListener
2016-07-15 17:49 652HttpSessionAttributeListener ... -
使用ServletContextAttributeListener
2016-07-15 16:47 797使用ServletContextAttr ... -
ServletRequestListener
2016-07-15 16:25 566ServletRequestListener接口 ... -
HttpSessionListener
2016-07-15 14:56 598HttpSessionListener接口 M ... -
ServletContextListener 接口
2016-07-15 12:16 585在 Servlet API 中有一个 Se ... -
ReflectASM,高性能的反射
2016-04-29 17:19 926http://www.oschina.net/p/r ... -
Java多线程与静态方法
2016-04-26 11:52 810Java多线程与静态方法 在多线程中使用静态方法会发生什么 ... -
log4j日志输出格式
2016-04-12 20:58 1073log4j日志输出格式 在LOG4J的配置文件中,l ... -
Servlet3.0
2016-04-12 16:58 654一、Servlet3.0介绍 Servlet3 ... -
log4j2 使用详解
2016-04-12 14:14 1415log4j2 使用详解 转载自 Blog of ... -
Eclipse jar打包和命令行运行
2016-04-08 10:44 2908?Eclipse jar打包和命令行运行 第1步: ... -
GRAPHICSMAGICK+IM4JAVA错误Cannot run program "gm": error=2
2015-05-19 15:27 4073在通过 GRAPHICSMAGICK+IM4JAVA ... -
GraphicsMagick安装、实时生成缩略图
2015-05-19 13:39 2371GraphicsMagick安装、实时生成缩略图 ...
相关推荐
在对网内主机进行监控时需要通过java获取远程机器的mac地址
Java/JSP获得客户端网卡MAC地址的三种方法解析
主要介绍了java编程实现获取机器IP地址及MAC地址的方法,实例分析了Java分别针对单网卡及多网卡的情况下获取服务器IP地址与MAC地址的相关技巧,需要的朋友可以参考下
java获取Centos7服务器网卡ip 子网掩码 默认网关 DNS 同时设置网卡 及 重启网卡参考
java 程序, 亲测。 获取计算机的网卡IP地址。 runttime 的调用。
刚刚发了一个获取电脑硬盘序列号的demo 想想还是把这个获取MAC地址的也发上来吧 请大家指点一二
允许这个测试类,就可以轻松的获取到本地连接的mac网卡地址了,就可以作为设备的唯一编码。
很容易的就可以获得机器的MAC(网卡)地址,是用java语言编写的
//Java获得CPU序列号和网卡Mac地址 /* 利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,...
C#程序源码,自己写的小工具,用于获取本机Mac地址,并对Mac地址进行AES加密及解密,已经过测试,方便使用。
NULL 博文链接:https://hylong05.iteye.com/blog/560600
很容易就可以获得 机器的MAC地址,我这使用java编写的。
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获取
10.JAVA获取系统当前的用户 7 11.javascript获取客户端网卡MAC地址和IP地址和计算机名 7 12.JAVA反射 8 13. 自定义ClassLoader 13 14. double保留两位数的两个方案 18 16. 用户输入输出,文件输入输出范例(1) 19 17....
一个Android连接WiFi设置的例子,可以显示WiFi列表,设置连接指定的WIFI,查看已保存wifi的密码(需要root权限),连接上wifi的详细信息:本机IP,本机MAC,网关,DNS,网卡接口名等信息。 之前上传过的DEMO:后来...
Wifi连接网络,通过程序你将了解到定义WifiManager对象,定义WifiInfo对象,获取网络连接列表,定义一个WifiLock,打开Wifi网卡,关闭Wifi网卡,检查当前Wifi网卡状态,扫描周边网络,每次点击扫描之前清空上一次的...
lib 官方jar包以及底层支撑文件问题解答1、mac下eclipse中配置java.library.pathMac下,eclipse中的配置方法:项目右键->属性->java build path->选择Libraries中的sigar.jar->在展开的Native library location中...
(4)侦听来源于指定 IP 地址的数据包,侦听指定目的 IP 地址的数据包 (5)获取数据包的详细信息,首部的各字段,包括源IP,目的IP,源端口,目的端口,源MAC,目的MAC等,将数据内容通过gbk方式解码 (4)侦听指定...