- package url;
- import java.net.*;
- import java.io.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
-
- /**
- * <p>Titre : URL sniffeur</p>
- * <p>Description : sniffeur d'URL(en gros...), visualiseur d'entête HTTP</p>
- * <p>Copyright : y'en a pas chui open, copyleft !!</p>
- * @author n0stra "LeDroW"
- * @version 1.0
- */
-
- public class URLsnif extends JPanel implements ActionListener
- {
- /*variables d'instance*/
- private String name;
- private boolean ok;
- private JScrollPane jsp1;
- private JScrollPane jsp2;
- private JTextArea jta1;
- private JTextArea jta2;
- private JTextField jtf;
-
- private URL u;
- private URLConnection connec;
-
- /*constructeur*/
- public URLsnif()
- {
- /*création des objets*/
- jta1 = new JTextArea(10,40);
- jta1.setEditable(false);
- jta1.setBackground(Color.lightGray);
- jta2 = new JTextArea(20,40);
- jta2.setEditable(false);
- jta2.setBackground(Color.lightGray);
- jsp1 = new JScrollPane(jta1);
- jsp2 = new JScrollPane(jta2);
- jtf = new JTextField(40);
- jtf.setText("http://");
- jtf.addActionListener(this);
- /*initialisation du panneau*/
- this.setLayout(new BorderLayout(5, 5));
- this.add(jtf, BorderLayout.NORTH);
- this.add(jsp1, BorderLayout.CENTER);
- this.add(jsp2, BorderLayout.SOUTH);
- }
-
- /*méthode de gestion de la validation de l'URL*/
- public void actionPerformed(ActionEvent e)
- {
- ok=true;
- try
- {
- name = jtf.getText();
- u = new URL(name);
- connec = u.openConnection();
- try
- {
- connec.connect();
- }
- catch(UnknownHostException ee)
- {
- jta1.append("URL inexistante : "+jtf.getText()+"\n");
- ok=false;
- }
- if(ok) jtf.selectAll();
- }
- catch(Exception ee)
- {
- //ee.printStackTrace();
- ok=false;
- }
- if(ok)
- {
- jta1.selectAll();jta1.setText("");
- this.getEntete();
- jta2.selectAll();jta2.setText("");
- this.getSource();
- }
- }
-
- /*méthode de récupération de l'entête HTTP*/
- private void getEntete()
- {
- String head;
- int i=0;
- jta1.append("\tENTETE !!!!!\n");
- while((head = connec.getHeaderField(i))!= null)
- {
- jta1.append(connec.getHeaderFieldKey(i)+" - "+head+"\n");
- i++;
- }
- }
-
- /*méthode de récupération du source de l'URL*/
- private void getSource()
- {
- try
- {
- InputStream flux = u.openStream();
- BufferedReader bfr = new BufferedReader(new InputStreamReader(flux));
- jta2.append("\tSOURCE !!!!!\n");
- String ligne;
- while((ligne = bfr.readLine())!= null)
- {
- jta2.append(ligne+"\n");
- }
- }
- catch(Exception ee)
- {
- ee.printStackTrace();
- }
- }
-
- /*methode d'exécution principale*/
- public static void main(String args[])
- {
- JFrame frame = new JFrame("_.:-=[_URLSniFF'_]=-:._");
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(1);
- }
- });
- frame.getContentPane().add(new URLsnif(), BorderLayout.CENTER);
- frame.setSize(600, 600);
- frame.setResizable(false);
- frame.setVisible(true);
- }
- }
package url;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Titre : URL sniffeur</p>
* <p>Description : sniffeur d'URL(en gros...), visualiseur d'entête HTTP</p>
* <p>Copyright : y'en a pas chui open, copyleft !!</p>
* @author n0stra "LeDroW"
* @version 1.0
*/
public class URLsnif extends JPanel implements ActionListener
{
/*variables d'instance*/
private String name;
private boolean ok;
private JScrollPane jsp1;
private JScrollPane jsp2;
private JTextArea jta1;
private JTextArea jta2;
private JTextField jtf;
private URL u;
private URLConnection connec;
/*constructeur*/
public URLsnif()
{
/*création des objets*/
jta1 = new JTextArea(10,40);
jta1.setEditable(false);
jta1.setBackground(Color.lightGray);
jta2 = new JTextArea(20,40);
jta2.setEditable(false);
jta2.setBackground(Color.lightGray);
jsp1 = new JScrollPane(jta1);
jsp2 = new JScrollPane(jta2);
jtf = new JTextField(40);
jtf.setText("http://");
jtf.addActionListener(this);
/*initialisation du panneau*/
this.setLayout(new BorderLayout(5, 5));
this.add(jtf, BorderLayout.NORTH);
this.add(jsp1, BorderLayout.CENTER);
this.add(jsp2, BorderLayout.SOUTH);
}
/*méthode de gestion de la validation de l'URL*/
public void actionPerformed(ActionEvent e)
{
ok=true;
try
{
name = jtf.getText();
u = new URL(name);
connec = u.openConnection();
try
{
connec.connect();
}
catch(UnknownHostException ee)
{
jta1.append("URL inexistante : "+jtf.getText()+"\n");
ok=false;
}
if(ok) jtf.selectAll();
}
catch(Exception ee)
{
//ee.printStackTrace();
ok=false;
}
if(ok)
{
jta1.selectAll();jta1.setText("");
this.getEntete();
jta2.selectAll();jta2.setText("");
this.getSource();
}
}
/*méthode de récupération de l'entête HTTP*/
private void getEntete()
{
String head;
int i=0;
jta1.append("\tENTETE !!!!!\n");
while((head = connec.getHeaderField(i))!= null)
{
jta1.append(connec.getHeaderFieldKey(i)+" - "+head+"\n");
i++;
}
}
/*méthode de récupération du source de l'URL*/
private void getSource()
{
try
{
InputStream flux = u.openStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(flux));
jta2.append("\tSOURCE !!!!!\n");
String ligne;
while((ligne = bfr.readLine())!= null)
{
jta2.append(ligne+"\n");
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
/*methode d'exécution principale*/
public static void main(String args[])
{
JFrame frame = new JFrame("_.:-=[_URLSniFF'_]=-:._");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
});
frame.getContentPane().add(new URLsnif(), BorderLayout.CENTER);
frame.setSize(600, 600);
frame.setResizable(false);
frame.setVisible(true);
}
}