2013年10月8日星期二

Java case get the client Mac address ? Rather than a local Mac address

I used to develop Java Liunx , now get the client to develop a demand for the Mac , I find some codes are able to get the machine's MAC address instead of the client 's MAC address, Which Big Brother , help out, look changed procedures, can not become a client -side execution services will be able to get the client MAC address , thank you ~



package kaga.it.Tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/ **
* Get MAC address
* @ author sunlightcs
*
* /
public class GetMacAddress {

/ **
* Get the current operating system name.
* return the name of the operating system such as : windows, Linux, Unix and so on. ;
* /
public static String getOSName () {
return System.getProperty ("os.name"). toLowerCase ();
}

/ **
* Get Unix card mac address.
* @ return mac address
* /
public static String getUnixMACAddress () {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
/ **
* Unix under the command , and generally show eth0 as the local primary NIC mac address information contains information
* /
process = Runtime.getRuntime (). exec ("ifconfig eth0");
bufferedReader = new BufferedReader (new InputStreamReader (process
. getInputStream ()));
String line = null; ;
int index = -1;
while ((line = bufferedReader.readLine ())! = null) {
/ **
* Find labeled string [hwaddr]
* /
index = ; line.toLowerCase (). indexOf ("hwaddr");
/ **
* found
* /
if (index ; ! = -1 ) {
/ **
* remove the mac address and remove the two side spaces
* /
mac = line.substring (index + "hwaddr". length () + 1). trim ();
break;
} ;
}
} catch (IOException e) { ;
e.printStackTrace ();
} finally {
try { ;
if (bufferedReader ;! = null) {
bufferedReader.close ();
} ;
} catch (IOException e1) {
e1.printStackTrace ();
}
bufferedReader = null; ;
process = null; ;
}

return mac;
}



/ **
* Get Linux network card mac address .
* @ return mac address
* /
public static String getLinuxMACAddress () {
String mac = null; ;
BufferedReader bufferedReader = null; ;
Process process = null; ;
try { ;
/ **
* linux under the command , generally taken as the local primary NIC eth0 information displayed contains mac address information
* /
process = ; Runtime.getRuntime (). exec ("ifconfig eth0");
bufferedReader = ; new BufferedReader (new InputStreamReader (process
. getInputStream ()));
String line = null;
int index = -1 ;
while (( line = bufferedReader.readLine ())! = null) {
index = line.toLowerCase (). indexOf (" hardware addresses " ) ;
/ **
* found
* /
if (index! = -1) {
/ **
* remove the mac address and remove the two side spaces
* /
mac = line.substring (index +4). trim ();
break;
}
} ;
} catch (IOException e) {
e.printStackTrace ( ) ;
} finally {
try { ;
if (bufferedReader! = null) {
bufferedReader.close ();
}
} catch ; (IOException e1) {
e1.printStackTrace ();
} ;
bufferedReader = ; null;
process = ; null;
}

return mac;
}

/ **
* Get widnows card mac address.
* @ return mac address
* /
public static String getWindowsMACAddress () {
String mac = null; ;
BufferedReader bufferedReader = null; ;
Process process = null; ;
try { ;
/ **
* windows under the command , the displayed information includes mac address
* /
process = ; Runtime.getRuntime (). exec ("ipconfig / all");
bufferedReader = ; new BufferedReader (new InputStreamReader (process
. getInputStream ()));
String line = null;
int index = -1 ;
while (( line = bufferedReader.readLine ())! = null) {
/ **
* Find labeled string [physical address]
* /
index = line.toLowerCase (). indexOf ("physical address");
if (index! = -1) {
index = line.indexOf (":");
if (index! = -1) {
/ **
* remove the mac address and remove the two side spaces
* /
mac = line.substring (index + 1). trim ();
}
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 method used for testing .
*
* @ param argc
* ; operating parameters.
* /
public static void main (String [] argc) {
String os = getOSName (); ;
System.out.println (os); ;
if (os.startsWith ("windows")) {





. .






}

  




2 条评论:

  1. 此评论已被作者删除。

    回复删除
  2. When your IP Address is more vulnerable to cyber attacks then you must use a technique to secure your connection.

    Thanks
    Silvester Norman

    Changing MAC Address

    回复删除