当然可以。。代码如下:
import java.io.*;public class Mac{
public static void main(String[] arg){
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.*;public class Mac{
public static void main(String[] arg){
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;
}
}
解决方案 »
- 请教有关hibernate自动建表问题
- 大家在开发JAVA Web项目的时候都用什么工具做?
- OUT型参数注册问题
- jsp 重定向?
- 大虾救命啊!! jdbc-odbc-access 为何我无论用何种方法进行查询总出现 Data type mismatch in criteria expression.
- 获得了一个字符串,想判断是不是一个有效的网址,如何做?
- 要求,清空 session 值,并且重定向到登陆画面
- int与String比较的问题
- 用javascript的switch条件判断没有用吗
- Spring Boot + mybatis 多数据源配置
- 【ACCESS数据库已经连通,但能读不能写】大家救救我吧.★★【up有分,高分求解】
- Java中如何返回多结果集
如果可以实现运行ipconfig
是不是可以实现一运行网面电脑就重启呢?
而且如果操作系统非win就会发生错误
,*********, , ,@@,
.****+++****,*: ,WW.
,***:.,,,.+****+ ,WW.
***., ,:***+ ,WW.
.**: ****+ ,WW.
+*+, ,.+++. :@@*, +@@:,WW.*@*.#@:
**: ,,,,,WWWWWW: ,WWWWWWWW.#WWWWWWW,+++,
,**: @WW@*WW. WWW**WWWW.#WWW#*WW* ::
,**: WWW*,.., #WW:,,.@WW.#WW+.,+WW,. .
+*+, .WWWW+, WW+, .WW.#W@. .WW,+#
.**, ,:WWWWW:,WW: ,WW.#W@, .WW,@@,
,***, ., ,.:#WWW.WW*, .WW.#W#, .WW.#+,
.***, +**, +,,,WWW:+WW. WWW.#W#, .WW. ,
,.*****+*****. WWWWWWW.,WWWWWWWWW.#W#, .WW,**,
,.********+., :WWWWWW+, .@WWWW@WW.#W#, .WW,**
,.+++++:, ,.:++:., ,:++:.++..++, ,++,,,
,,,,, ,,,, ,,, ,,,,,, ,,
用http://bbs.soulsky.net/pub/ascii/做的。
<% Option Explicit %>
<html>
<head>
<title>查看网络设置</title>
</head>
<body bgcolor="#FFFFFF">
<%
dim strHost
dim oShell,oFS,oTF
dim i,Data,tempData
strHost="ipconfig"
Set oShell = Server.CreateObject("Wscript.Shell")
oShell.Run "%ComSpec% /c ipconfig > C:\" & strHost & ".txt", 0, True
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oTF = oFS.OpenTextFile("C:\" & strHost & ".txt")
Do While Not oTF.AtEndOfStream
Data = Trim(oTF.Readline)
If i > 2 Then
tempData = tempData & Data & "<BR>"
End If
i = (i + 1)
Loop
response.write tempData
oTF.Close
oFS.DeleteFile "C:\" & strHost & ".txt"
Set oFS = Nothing
%>
</font>
</body>
</html>
原理就是截取DOS的ping命令的输出而已代码如下:
package net.cqpower.util;import java.io.*;
/**
* <p>Title: puwei CRM</p>
* <p>Description: Chong Qing puwei CRM</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: puwei</p>
* @author ZhangPu
* @version 1.0
*/public class MAC2000
{
/**
* Description : get the MAC of localhost.
* @return
*/
public static String getMAC()
{
String strMAC = "";
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);
strMAC = procAll(netdata);
}catch(IOException e)
{
System.out.println("error="+e);
return null;
}
return strMAC;
} 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;
} /**
* Discription : test inside of class.
* @param arg
*/
public static void main(String[] arg)
{
String strMAC = MAC2000.getMAC(); System.out.println("Your Mac Address=" + strMAC);
}}