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="";
}