A voir également:
- Adresse MAC de l'usager de ma page web
- Adresse mac - Guide
- Supprimer une page word - Guide
- Darkino nouvelle adresse - Guide
- Rechercher ou entrer l'adresse - Guide
- Traduire une page web - Guide
4 réponses
J'ai une applet qui peut lire l'adresse mac du client qui se connecte à ton application.
Je voudrai que tu me donnes la suite parce que j'ai du mal à le faire fonctionner.
import java.net.InetAddress;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.applet.Applet;
/**
* Classe permettant de récupérer l'adresse MAC d'un ordinateur.
*/
public class appletMac extends Applet{
/**
* Méthode Main de l'application
*
* @param args
*/
public static void main (String args []){
appletMac macAppl = new appletMac();
macAppl.init();
}
public void init() {
restart();
}
public void restart() {
try
{
System.out.println("Information Réseau Local");
System.out.println(" Système d'exploitation : " +System.getProperty("os.name"));
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getHostName());
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getHostAddress());
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getLocalHost());
System.out.println(" Adresse MAC : " + getMacAddress());
}
catch (Throwable t)
{
t.printStackTrace();
}
}
/**
* Méthode invoquant le traitement à effectuer pour récupérer l'adresse MAC
* de l'ordinateur sur lequel on se trouve suivant le système
* d'exploitation.
*
* @return L'adresse MAC
*
* @throws IOException
*/
public static String getMacAddress() throws IOException {
String os = System.getProperty("os.name");
try{
if (os.startsWith("Windows")){
return windowsParseMacAddress(windowsRunIpConfigCommand());
}else{
throw new IOException("Système d'exploitation non supporté : " + os);
}
}catch (ParseException ex){
ex.printStackTrace();
throw new IOException(ex.getMessage());
}
}
// *************** Commande de récupération des informations réseau ***************//
/**
* Méthode récupérant les informations réseau sous Windows
* @return toutes les informations réseau
* @throws IOException
*/
private static String windowsRunIpConfigCommand() throws IOException {
Process p = Runtime.getRuntime().exec("ipconfig /all");
InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
StringBuffer buffer = new StringBuffer();
for (; ; ){
int c = stdoutStream.read();
if (c == -1)
break;
buffer.append( (char) c);
}
String outputText = buffer.toString();
stdoutStream.close();
return outputText;
}
private static String windowsParseMacAddress(String ipConfigResponse) throws ParseException
{
String localHost = null;
try
{
localHost = InetAddress.getLocalHost().getHostAddress();
}catch (java.net.UnknownHostException ex){
ex.printStackTrace();
throw new ParseException(ex.getMessage(), 0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
String lastMacAddress = null;
while (tokenizer.hasMoreTokens()){
String line = tokenizer.nextToken().trim();
// see if line contains IP address
if (line.endsWith(localHost) && lastMacAddress != null){
return lastMacAddress;
}
// see if line contains MAC address
int macAddressPosition = line.indexOf(":");
if (macAddressPosition <= 0)
continue;
String macAddressCandidate = line.substring(macAddressPosition + 1).trim();
if (windowsIsMacAddress(macAddressCandidate)){
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException("cannot read MAC address from [" +ipConfigResponse + "]", 0);
ex.printStackTrace();
throw ex;
}
private static boolean windowsIsMacAddress(String macAddressCandidate)
{
Pattern macPattern = Pattern
.compile("[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}");
Matcher m = macPattern.matcher(macAddressCandidate);
return m.matches();
}
}
Je voudrai que tu me donnes la suite parce que j'ai du mal à le faire fonctionner.
import java.net.InetAddress;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.applet.Applet;
/**
* Classe permettant de récupérer l'adresse MAC d'un ordinateur.
*/
public class appletMac extends Applet{
/**
* Méthode Main de l'application
*
* @param args
*/
public static void main (String args []){
appletMac macAppl = new appletMac();
macAppl.init();
}
public void init() {
restart();
}
public void restart() {
try
{
System.out.println("Information Réseau Local");
System.out.println(" Système d'exploitation : " +System.getProperty("os.name"));
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getHostName());
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getHostAddress());
System.out.println(" IP/Localhost: " +InetAddress.getLocalHost().getLocalHost());
System.out.println(" Adresse MAC : " + getMacAddress());
}
catch (Throwable t)
{
t.printStackTrace();
}
}
/**
* Méthode invoquant le traitement à effectuer pour récupérer l'adresse MAC
* de l'ordinateur sur lequel on se trouve suivant le système
* d'exploitation.
*
* @return L'adresse MAC
*
* @throws IOException
*/
public static String getMacAddress() throws IOException {
String os = System.getProperty("os.name");
try{
if (os.startsWith("Windows")){
return windowsParseMacAddress(windowsRunIpConfigCommand());
}else{
throw new IOException("Système d'exploitation non supporté : " + os);
}
}catch (ParseException ex){
ex.printStackTrace();
throw new IOException(ex.getMessage());
}
}
// *************** Commande de récupération des informations réseau ***************//
/**
* Méthode récupérant les informations réseau sous Windows
* @return toutes les informations réseau
* @throws IOException
*/
private static String windowsRunIpConfigCommand() throws IOException {
Process p = Runtime.getRuntime().exec("ipconfig /all");
InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
StringBuffer buffer = new StringBuffer();
for (; ; ){
int c = stdoutStream.read();
if (c == -1)
break;
buffer.append( (char) c);
}
String outputText = buffer.toString();
stdoutStream.close();
return outputText;
}
private static String windowsParseMacAddress(String ipConfigResponse) throws ParseException
{
String localHost = null;
try
{
localHost = InetAddress.getLocalHost().getHostAddress();
}catch (java.net.UnknownHostException ex){
ex.printStackTrace();
throw new ParseException(ex.getMessage(), 0);
}
StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
String lastMacAddress = null;
while (tokenizer.hasMoreTokens()){
String line = tokenizer.nextToken().trim();
// see if line contains IP address
if (line.endsWith(localHost) && lastMacAddress != null){
return lastMacAddress;
}
// see if line contains MAC address
int macAddressPosition = line.indexOf(":");
if (macAddressPosition <= 0)
continue;
String macAddressCandidate = line.substring(macAddressPosition + 1).trim();
if (windowsIsMacAddress(macAddressCandidate)){
lastMacAddress = macAddressCandidate;
continue;
}
}
ParseException ex = new ParseException("cannot read MAC address from [" +ipConfigResponse + "]", 0);
ex.printStackTrace();
throw ex;
}
private static boolean windowsIsMacAddress(String macAddressCandidate)
{
Pattern macPattern = Pattern
.compile("[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}");
Matcher m = macPattern.matcher(macAddressCandidate);
return m.matches();
}
}
crabs
Messages postés
908
Date d'inscription
lundi 18 avril 2005
Statut
Membre
Dernière intervention
3 août 2008
506
8 oct. 2005 à 19:32
8 oct. 2005 à 19:32
Salut,
Le mieux que tu pourra avoir c'est l'adresse mac du dernier routeur qu'il y a
entre le PC qui surfe et ton serveur WEB.
Donc tout le monde devrait avoir la même adresse MAC en arrivant sur ton site.
Le seul système fiable reste de gérer un espace membre (inscription+login) afin
d'être sur que les personnes ne votent qu'une fois.
A+, Crabs
Le mieux que tu pourra avoir c'est l'adresse mac du dernier routeur qu'il y a
entre le PC qui surfe et ton serveur WEB.
Donc tout le monde devrait avoir la même adresse MAC en arrivant sur ton site.
Le seul système fiable reste de gérer un espace membre (inscription+login) afin
d'être sur que les personnes ne votent qu'une fois.
A+, Crabs
Utilisateur anonyme
9 oct. 2005 à 00:11
9 oct. 2005 à 00:11
merci de ta réponce mais si quelqu'un d'autre a une idée....
si c'est possible d'avoir l'IP du client (pas seulement celle du dernier routeur) pourquoi est-ce que je ne peux pas faire de requète ARP pour savoir le MAC....???
merci encore.
si c'est possible d'avoir l'IP du client (pas seulement celle du dernier routeur) pourquoi est-ce que je ne peux pas faire de requète ARP pour savoir le MAC....???
merci encore.
crabs
Messages postés
908
Date d'inscription
lundi 18 avril 2005
Statut
Membre
Dernière intervention
3 août 2008
506
9 oct. 2005 à 08:37
9 oct. 2005 à 08:37
ARP repose sur du broadcast UDP, qui ne passe pas les routeurs
25 janv. 2009 à 14:07
Si oui comment l'utiliser ?
Merci