zina
-
11 sept. 2013 à 14:03
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024
-
12 sept. 2013 à 15:26
bonjour
je suis débutant en java
j'ai une classe qui recuperer @ mac d'un ordinateur
je voulais afficher cette @ dans jtextfield d'une fenetre
voila la classe @ mac
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package macadresse;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
/**
*
* @author NewMedia
*/
public class MacAdresse {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// Obtenir l'adresse IP de la machine locale
InetAddress address = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
byte[] mac = ni.getHardwareAddress();
// Afficher l'adresse Mac
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : "");
}
}
}
et la classe frame
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package macadresse;
/**
*
* @author NewMedia
*/
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jColorChooser1 = new javax.swing.JColorChooser();
jColorChooser2 = new javax.swing.JColorChooser();
jColorChooser3 = new javax.swing.JColorChooser();
jColorChooser4 = new javax.swing.JColorChooser();
ADRESS = new javax.swing.JPanel();
adr_mac = new javax.swing.JTextField();
code_mac = new javax.swing.JTextField();
ok = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
annuler = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024103 11 sept. 2013 à 16:25
Hello,
Merci d'éditer ton message afin de rajouter les balises code pour plus de lisibilité.
Merci également de nous préciser ton problème, ton point bloquant,... Parce là, en l'état, je ne sais pas quoi te dire de plus
zaynoubagl
Messages postés58Date d'inscriptionmercredi 11 septembre 2013StatutMembreDernière intervention19 octobre 2014 11 sept. 2013 à 16:31
je suis entraine de securiser mon application java
la methode et de recuperer l'adresse mac et convertir en decimale puis afficher dans jtextfield et l'utilisateur demande l'autre code (@ mac en decimale) puis aprés la vrifiaction je lance execution de l'application
zaynoubagl
Messages postés58Date d'inscriptionmercredi 11 septembre 2013StatutMembreDernière intervention19 octobre 2014 11 sept. 2013 à 16:33
public static void main(String[] args) throws Exception {
// Obtenir l'adresse IP de la machine locale
InetAddress address = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
byte[] mac = ni.getHardwareAddress();
// Afficher l'adresse Mac
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : "");
}
}
}
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024103 11 sept. 2013 à 16:40
Euh...c'est quoi que tu n'as pas compris dans ce que j'ai écris?
zaynoubagl
Messages postés58Date d'inscriptionmercredi 11 septembre 2013StatutMembreDernière intervention19 octobre 2014 11 sept. 2013 à 16:47
adr_mac.setText ( adr_mac.getText () + System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : ""));
ne retourne pas @ mac
elle affiche
java.io.PrintStream@cb36fa dans le jtextfield
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024103 11 sept. 2013 à 17:00
Après un rapide test, ceci fonctionne chez moi:
import java.net.InetAddress;
import java.net.NetworkInterface;
public class MacAdress {
/**
* @param args
*/
public static void main(final String[] args) {
try {
// Obtenir l'adresse IP de la machine locale
final InetAddress address = InetAddress.getLocalHost();
final NetworkInterface ni = NetworkInterface.getByInetAddress(address);
final byte[] mac = ni.getHardwareAddress();
// Afficher l'adresse Mac
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : "");
}
} catch (final Exception e) {
System.out.println("exception");
}
}
}
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024103 Modifié par BunoCS le 11/09/2013 à 17:18
Ceci devrait fonctionner:
try {
final InetAddress address = InetAddress.getLocalHost();
final NetworkInterface ni = NetworkInterface.getByInetAddress(address);
final byte[] mac = ni.getHardwareAddress();
final StringBuilder sb = new StringBuilder("");
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X", mac[i]));
}
adr_mac.setText(sb.toString());
} catch (final Exception e) {
// todo
}
@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
zaynoubagl
Messages postés58Date d'inscriptionmercredi 11 septembre 2013StatutMembreDernière intervention19 octobre 2014 11 sept. 2013 à 17:26
merci bcp je suis debutant en java merci merci
ca fonctionne mais j'ai un autre probleme quant je voulais transformer cette chaine hexadecimale en decimal
elle prend sauf les 7 premier numero
voici la classe
902B3478E864
elle faire la transformation sauf pour
902B347
//////////////////////
package macadresse;
import java.io.*;
import java.lang.*;
public class HexadecimalToDecimal{
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Hexadecimal number:");
String str= bf.readLine();
int i= Integer.parseInt(str, 32);
11 sept. 2013 à 16:31
la methode et de recuperer l'adresse mac et convertir en decimale puis afficher dans jtextfield et l'utilisateur demande l'autre code (@ mac en decimale) puis aprés la vrifiaction je lance execution de l'application
11 sept. 2013 à 16:33
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
public class MacAdresse {
public static void main(String[] args) throws Exception {
// Obtenir l'adresse IP de la machine locale
InetAddress address = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
byte[] mac = ni.getHardwareAddress();
// Afficher l'adresse Mac
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : "");
}
}
}
11 sept. 2013 à 16:40
11 sept. 2013 à 16:47
ne retourne pas @ mac
elle affiche
java.io.PrintStream@cb36fa dans le jtextfield
11 sept. 2013 à 17:00