- 浏览: 856879 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
yukang1:
蚂蚁lovejing 写道我也出现与楼上相同的问题。查了一些资 ...
Spring中实现文件上传 -
史玉凤:
必须用ie浏览器
javascript获取客户端网卡MAC地址和IP地址和计算机名 -
蚂蚁lovejing:
我也出现与楼上相同的问题。查了一些资料,描述的跟楼主的博文差不 ...
Spring中实现文件上传 -
温柔一刀:
djlijian 写道最近也在研究redis,如何在项目中使用 ...
Redis 常见的性能问题和解决方法 -
djlijian:
最近也在研究redis,如何在项目中使用呢?感觉网上的资料太少 ...
Redis 常见的性能问题和解决方法
java 代码
- 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;
- }
- }
发表评论
-
Spring Integration 1.0 发布
2008-11-20 14:34 2081终于迎来了spring integration的第一个fina ... -
When To Use Mock Objects?
2008-06-10 10:18 1572The real object has nondeterm ... -
JACOB发送传真
2008-03-21 19:46 3765JACOB一个JAva-COM中间件.通过这个组件你可以在Ja ... -
IDEA快捷键
2007-04-30 12:16 5539最常用快捷键 1.Ctrl+E,可以显示最近编辑的文件列表 2 ... -
Ant+Tomcat自动部署的小问题
2007-02-14 18:00 8405今天用Ant对dms系统进行Tomcat的自动部署。 通过a ... -
FCKeditor-2.3在线编辑器,可以直接用的(java版)
2007-02-12 12:11 39376初次使用FCKeditor编辑器, 在网上搜索了半天也没有找 ... -
Java是剑客-飘逸;.NET是刀客-霸道
2006-12-26 19:17 4908网上看到的一篇 ... -
常用到的Eclipse快捷键
2006-11-11 12:13 3357Ctrl+s 存盘 Ctrl+/ ... -
java操作Excel、PDF文件
2006-10-09 16:41 36205下面这些是在开发中用到的一些东西,有的代码贴的不是完整的,只是 ... -
通过SCJP考试,说点体会和感受
2006-04-25 18:58 4845我就随便说说哈,不认可的朋友就当没有看见哈! 1、首先声明下 ... -
使用smartupload进行文件的上传下载
2006-06-07 23:30 5263jspSmartUpload是由www.jspsmart.co ... -
log4j的配置文件例子
2006-07-09 04:27 2991log4j的配置文件例子,非常方便的一个开源日志软件,一直用它 ... -
javaBean数据库连接池
2006-07-09 04:35 2668实现简单的数据库连接池: java 代码 / ... -
用java实现浮点数的精确计算
2006-07-13 22:28 2880问题的提出: 如果我们编译运行下面这个程序会看到什么? j ... -
工厂模式
2006-07-13 22:30 5103简单工厂模式 1. 目的 工厂模式就是专门负 ... -
61条面向对象设计的经验原则
2006-07-13 22:51 1819(1)所有数据都应该隐藏在所在的类的内部。 (2)类的使用者必 ... -
追MM与java的32种模式
2006-07-13 22:55 1806创建型模式 1、FACTORY—追MM少不了请吃饭了,麦当 ... -
OO的五大原则
2006-07-14 19:25 4716OO的五大原则是指SRP ... -
JAVA系列之对象的序列化与反序列化
2006-07-17 09:09 177801 简介 对象序列化(Seria ... -
基于Java的IDEA加密算法探讨
2006-08-08 20:07 2092摘要:本文介绍了在JAVA环境下如何实现IDEA对称加密算法。 ...
相关推荐
java获取本机网卡地址工具类,ipv4地址获取,根据主机名获取主网卡地址。
java获取Centos7服务器网卡ip 子网掩码 默认网关 DNS 同时设置网卡 及 重启网卡参考
主要介绍了java编程实现获取机器IP地址及MAC地址的方法,实例分析了Java分别针对单网卡及多网卡的情况下获取服务器IP地址与MAC地址的相关技巧,需要的朋友可以参考下
JAVA得到网卡物理地址(windows和Linux)
java获取本机网卡的MAC地址,/** * 测试用的main方法. * * @param argc * 运行参数. */ public static void main(String[] argc) { String os = getOSName(); System.out.println(os); if(os....
Java中获取IP地址,主机名称,网卡地址
使用的是J2SE的ProcessBuilder类执行外部的程序,相对于 Runtime.exec 它更方便,可以设置环境变量等。这里使用它在windows下读取物理网卡的地址。供大家参考。
java查询网卡地址工具((因为java编写的软件,所以需要运行环境JRE环境方可运行!!)
jpcap.jar,使用java获取网卡所需的jar包
在对网内主机进行监控时需要通过java获取远程机器的mac地址
TCHAR rgtsz[4][10] = {_T("网卡序号"),_T("Mac地址")}; LV_COLUMN lvcolumn; CRect rect; m_ctrlAdaptersLst.GetWindowRect(&rect); for(int i=0;i;i++) { lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_...
刚刚发了一个获取电脑硬盘序列号的demo 想想还是把这个获取MAC地址的也发上来吧 请大家指点一二
Qt获取IP地址、MAC地址等网卡信息,区分本地网卡、无线网卡和虚拟网卡
Java/JSP获得客户端网卡MAC地址的三种方法解析
C#实现获取多网卡IP地址方法,该方法可以遍历出所有网卡的IP地址。
java使用siger 获取服务器硬件信息(CPU 内存 网络 io等)
PB API 取IP 纯PB获取IP、网卡地址
注册以后调用,可以获取客户端网卡地址 双网卡也可以
VisualC 实效编程 90 获取网卡地址VisualC 实效编程 90 获取网卡地址VisualC 实效编程 90 获取网卡地址VisualC 实效编程 90 获取网卡地址VisualC 实效编程 90 获取网卡地址VisualC 实效编程 90 获取网卡地址VisualC ...
在线获取客户端网卡地址,asp.net代码