Nao tenho certeza se esta na area certa, mas…
Estou procurando uma forma de Pegar o Mac e o nome da maquina do cliente que esta acessando o applet, o codigo funciona em win xp, mas nao funciona em win 7, existe alguma forma de encontrar no win 7 ?
Aguardo, obrigado dês de já a todos.
Seque a classe completa :
package userData;
import java.io.*;
import java.net.*;
import java.util.Enumeration;
public class GetUserData {
static final byte[] HEX_CHAR_TABLE = {
(byte) '0', (byte) '1', (byte) '2', (byte) '3',
(byte) '4', (byte) '5', (byte) '6', (byte) '7',
(byte) '8', (byte) '9', (byte) 'A', (byte) 'B',
(byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F'
};
public String getMac() throws MacAddressException {
Enumeration<NetworkInterface> infoNetInterface = null;
try {
infoNetInterface = NetworkInterface.getNetworkInterfaces();
} catch (SocketException ex) {
throw new MacAddressException();
}
while (infoNetInterface.hasMoreElements()) {
NetworkInterface macaddress;
macaddress = infoNetInterface.nextElement();
try {
if (macaddress != null && macaddress.getHardwareAddress() != null) {
String mac = new String(macaddress.getHardwareAddress());
if (mac != null) {
return getHexString(macaddress.getHardwareAddress());
}
}
} catch (UnsupportedEncodingException ex) {
throw new MacAddressException();
} catch (SocketException ex) {
throw new MacAddressException();
}
}
return null;
}
public String getHexString(byte[] mac)
throws UnsupportedEncodingException {
byte[] macnum = new byte[2 * mac.length + 5];
int index = 0;
for (byte b : mac) {
int v = b & 0xFF;
macnum[index++] = HEX_CHAR_TABLE[v >>> 4];
macnum[index++] = HEX_CHAR_TABLE[v & 0xF];
}
return new String(macnum, "ASCII");
}
public String formatMacAddress(String mac) {
String macfinal;
macfinal = mac.substring(0, 2) + "-";
for (int i = 2; i <= 10; i += 2) {
macfinal += mac.substring(i, i + 2);
if (i < 10) {
macfinal += "-";
}
}
return macfinal;
}
public String getFormatedMacAddress() throws MacAddressException {
String macfinal = getMac().substring(0, 12);
return macfinal;
}
public String getPcName() throws pcNameExceptions {
try {
InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
throw new pcNameExceptions();
}
java.net.InetAddress i = null;
try {
i = java.net.InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
throw new pcNameExceptions();
}
return i.getHostName();
}
}