Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1712 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Programmation : pb avec inetaddress

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Programmation : pb avec inetaddress

n°1644747
bugybugs
euhhh voila quoi !
Posté le 18-11-2007 à 14:30:35  profilanswer
 

Bon voila j'essaye de faire un programme pour :
- chercher toutes les personnes connecter a un reseau lan en affichant l'adresse utilisé et le nom du l'utilisateur
- donner ttes les @ ip d'un nom par exemple "www.google.com" c'est a dire connaitre toutes les adresses qui le compose
- ce qui en resulte doit etre enregistrable (ok)
 
tous ca suivant la progression en venir a faire une sorte de "msn" on va dire donc pourvoir selectionné une address et pouvoir communiquer avec
 
merci d'avance

mood
Publicité
Posté le 18-11-2007 à 14:30:35  profilanswer
 

n°1644749
bugybugs
euhhh voila quoi !
Posté le 18-11-2007 à 14:32:08  profilanswer
 

package jul;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
 
public class Ip extends javax.swing.JFrame {
     
     
    public Ip() {
       try {
            initComponents();
            InetAddress Moi = InetAddress.getLocalHost();
            MonIP.setText( "Mon nom : "+Moi.getHostName() +"       "+"Mon @ IP :  "+Moi.getHostAddress());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }  
     
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        Recherch = new javax.swing.JButton();
        TextNom = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextIP = new javax.swing.JTextArea();
        MonIP = new javax.swing.JLabel();
        AllAddress = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        BoutAllAddress = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        TextAllIP = new javax.swing.JTextArea();
        TextBaseIP = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        Save = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        About = new javax.swing.JMenuItem();
 
        setTitle("IP LAN" );
 
        Recherch.setText("Rechercher" );
        Recherch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecherchActionPerformed(evt);
            }
        });
 
        TextNom.setText(" " );
 
        TextIP.setColumns(20);
        TextIP.setRows(5);
        jScrollPane1.setViewportView(TextIP);
 
        AllAddress.setText("Toutes @ IP" );
 
        jLabel1.setText("Nom de la machine :" );
 
        jLabel2.setText("@ IP de la machine :" );
 
        BoutAllAddress.setText("Rechercher all @ IP" );
        BoutAllAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BoutAllAddressActionPerformed(evt);
            }
        });
 
        TextAllIP.setColumns(20);
        TextAllIP.setRows(5);
        jScrollPane2.setViewportView(TextAllIP);
 
        TextBaseIP.setText("192.168.0." );
 
        jLabel3.setText("jLabel3" );
 
        Save.setText("File" );
 
        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Save" );
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        Save.add(jMenuItem1);
 
        jMenuBar1.add(Save);
 
        jMenu2.setText("About" );
 
        About.setText("About" );
        About.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutActionPerformed(evt);
            }
        });
        jMenu2.add(About);
 
        jMenuBar1.add(jMenu2);
 
        setJMenuBar(jMenuBar1);
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(TextNom)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel2))
                    .addComponent(AllAddress)
                    .addComponent(Recherch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1)
                    .addComponent(MonIP))
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(BoutAllAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                    .addComponent(TextBaseIP)
                    .addComponent(jScrollPane2))
                .addContainerGap(69, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(MonIP, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(BoutAllAddress))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(TextNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AllAddress)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Recherch))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(TextBaseIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    private void RecherchActionPerformed(java.awt.event.ActionEvent evt) {                                          
       if(AllAddress.isValid()==true){
             try {
                InetAddress[] addr = InetAddress.getAllByName(TextNom.getText());
                for (int i = 0; i < addr.length; i++) {
                   String a = addr[i].toString();
                   TextIP.setText(a);
                }
            } catch (Exception ex) {
                 ex.printStackTrace();
            }
        }
       
        else{  
             try{
             
                InetAddress host=InetAddress.getByName(TextNom.getText());
                TextIP.setText(host.getHostAddress());
        }
            catch(Exception e){
                e.printStackTrace();
        }
    }
    }                                        
 
    private void AboutActionPerformed(java.awt.event.ActionEvent evt) {                                      
        JOptionPane.showMessageDialog(null,
    "Créé par Jul",
    "About",
    JOptionPane.INFORMATION_MESSAGE);
    }                                      
 
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            FileWriter addresse;
            recupDate();
            String nom = TextNom.getText();
            nomFichier=JOptionPane.showInputDialog("entrer un nom de fichier" );
            affichage="\r\n"+date+"\r\n";
             
            try{
                String text = this.TextIP.getText();
                addresse = new FileWriter(nomFichier+".txt",true);
                addresse.write(affichage);
                 
                addresse.write(nom+":"+text+"\r\n" );
                addresse.close();
                 
            }
            catch(Exception e){
                e.printStackTrace();
            }
    }                                          
 
    private void BoutAllAddressActionPerformed(java.awt.event.ActionEvent evt) {                                                
       int n = 0;
       while( n < 255 ){
            try {
                String p = TextBaseIP.getText() + n;
                InetAddress o = InetAddress.getByName(p);
                String h = o.getHostName();
                if (p.equalsIgnoreCase(o.toString()) == true) {
                    TextAllIP.setText("" );
                    //TextAllIP.setText(o.toString() +"  :  Address no utils\r\n" );
                }  
                else {
                    TextAllIP.setText(o.toString() +"  :  "+ h +"\r\n" );
                }  
            }
            catch(Exception e){
                e.printStackTrace();
            }
       }
    }                                              
     
    public String recupDate(){
Date maDate = new Date();
date=maDate.toString();
return date;
}
     
    public static void main(String [] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ip().setVisible(true);
            }
        });
    }    
    // Variables declaration - do not modify                      
    private javax.swing.JMenuItem About;
    private javax.swing.JCheckBox AllAddress;
    private javax.swing.JButton BoutAllAddress;
    private javax.swing.JLabel MonIP;
    private javax.swing.JButton Recherch;
    private javax.swing.JMenu Save;
    private javax.swing.JTextArea TextAllIP;
    private javax.swing.JTextField TextBaseIP;
    private javax.swing.JTextArea TextIP;
    private javax.swing.JTextField TextNom;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration                    
public String affichage="";
public String hote="";
public String nomFichier="";
public Date maDate=null;
public String date="";
}

n°1645113
sircam
I Like Trains
Posté le 19-11-2007 à 10:37:28  profilanswer
 

Tu ne poses pas de question. J'en déduis que tu veux qu'on donne une solution toute faite à ton problème, çàd qu'on reprenne le code et qu'on le corrige? J'ai bon?


---------------
Now Playing: {SYNTAX ERROR AT LINE 1210}
n°1645491
bugybugs
euhhh voila quoi !
Posté le 19-11-2007 à 21:01:45  profilanswer
 

Le probleme c'est au niveau de de laffichage direct de mon address IP et du nom si je ne le met pas ca marche a moitier  
metton je met "tit" comme nom a rechercher il me di quil ya un prbleme au niveau de "native method" et sinon la recherche de tte les addresse IP utilisé ds le reseau le bouton reste comme bloqué et rien ne se passe

n°1645513
sircam
I Like Trains
Posté le 19-11-2007 à 22:41:52  profilanswer
 

Super, mais pourrais-tu stp reformuler, avec de la ponctuation et en te souciant un minumum de l'orthographe, pour les vieux qui te lisent. En évitant d'écrire phonétiquement, en quelque sorte. :jap:


---------------
Now Playing: {SYNTAX ERROR AT LINE 1210}

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Programmation : pb avec inetaddress

 

Sujets relatifs
Programmation : Langage SAP et PLCAide programmation java;: modeliser une blibliotheque urgent svp
petit programme en java = gros souci de programmationLa programmation en Kernel cela existe ???
probleme avec programmation csharpConaissez-vous la programmation en logique floue ?
programmationProgrammation logiciel de laboratoire
[TI-84]Programmation pour intervalomètreErreurs de programmation donnant une page blanche...
Plus de sujets relatifs à : Programmation : pb avec inetaddress


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)