Turn from: http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=124&threadID=28320&messageID=171767
Java obtains the CPU serial number and the network card MAC address
/*
Using the commands of the runtime call operating system, the specific commands depend on the different operating systems, and do not invoke the Runtime.getruntime (). EXEC (String) interface to use Runtime.getruntime (). EXEC ( String[]) This interface, or the execution of complex commands can be problematic. Examples are as follows (take the number of CPUs, other similar):
To define a command:
Windowscmd = "cmd.exe/c echo%number_of_processors%";//windows Special
Solariscmd = {"/bin/sh", "-C", "/usr/sbin/psrinfo | Wc-l "};
Aixcmd = {"/bin/sh", "-C", "/USR/SBIN/LSDEV-CC processor | Wc-l "};
Hpuxcmd = {"/bin/sh", "-C", "Echo/" map/"|/usr/sbin/cstm | grep CPU | wc-l"};
Linuxcmd = {"/bin/sh", "-C", "Cat/proc/cpuinfo | grep ^process | Wc-l "};
Then judge the system:
OS = System.getproperty ("Os.name"). toLowerCase ();
Call different commands depending on the operating system.
*/
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import Java.io.LineNumberReader;
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 ("172.18.8.225"));
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.