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

  FORUM HardWare.fr
  Programmation
  Java

  scan réseau+scan de port

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

scan réseau+scan de port

n°2187918
chimo01
Posté le 29-04-2013 à 02:53:53  profilanswer
 

Bonjour ,
 
mon projet consiste à réaliser une application de scan réseau et de port
mes problèmes  :( :
1/  au niveau de l'interface scan de port le menu est visible au début mais lorsque je démarre le scan , le sous menu devient invisible  
2/ comment je fait l'opération d'enregistrer sous des listes des ports retouvés (dans le textarea).
3/ dans le menu édition j'ai les opération couper, copier et coller . est ce que je doit mettre dans chaque évenement
4/au niveau de l'interface scan réseau, j'ai fait l'affichage des adresses ip , hostname et adresse mac. comment je peut afficher directement l'adresse ip de la machine retrouvée dans champ adresse ip de l'interface scan de port.
 
voici mes codes :
 

Code :
  1. package lanscanner;
  2. import java.net.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.JFrame;
  6. import javax.swing.JMenu;
  7. import javax.swing.JMenuBar;
  8. import javax.swing.JMenuItem;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.KeyStroke;
  11. public class PortScanner extends JFrame{
  12. Socket s;
  13. int startPort,endPort;
  14. Label l1;
  15. TextField hostName,fromPort,toPort;
  16. TextArea log;
  17. Label host,from,to,label;
  18. Button scan,reset;
  19. int fp,tp;
  20. String h;
  21. static boolean close=false;
  22. Dialog d;
  23. JFrame f=new JFrame("Scanner de ports" );
  24. JMenuBar barre = new JMenuBar();
  25. public PortScanner(){
  26.  /*      MENU     */
  27.  JMenuBar barre = new JMenuBar();
  28.  JMenu fichier = new JMenu("Fichier" );
  29.  JMenu edition = new JMenu("Edition" );
  30.  JMenu aide = new JMenu("Aide" );
  31.  JMenuItem enregistrer = new JMenuItem("Enregistrer sous..." );
  32.  JMenuItem quitter = new JMenuItem("Quitter" );
  33.  JMenuItem couper = new JMenuItem("Couper" );
  34.  JMenuItem copier = new JMenuItem("Copier" );
  35.  JMenuItem coller = new JMenuItem("Coller" );
  36.  JMenuItem about = new JMenuItem("About" );
  37.  barre.add(fichier);
  38.  barre.add(edition);
  39.  barre.add(aide);
  40.  fichier.add(enregistrer);
  41.  fichier.addSeparator();
  42.  fichier.add(quitter);
  43.  edition.add(couper);
  44.  edition.add(copier);
  45.  edition.add(coller);
  46.  aide.add(about);
  47.  enregistrer.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,KeyEvent.CTRL_MASK));
  48.  fichier.add(enregistrer);
  49.  quitter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,KeyEvent.CTRL_MASK));
  50.  fichier.add(quitter);
  51.  couper.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,KeyEvent.CTRL_MASK));
  52.  edition.add(couper);
  53.  copier.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,KeyEvent.CTRL_MASK));
  54.  edition.add(copier);
  55.  coller.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,KeyEvent.CTRL_MASK));
  56.  edition.add(coller);
  57.  quitter.addActionListener(new ActionListener() {
  58.           public void actionPerformed(ActionEvent e) {
  59.              System.exit(0);
  60.           }
  61.   });
  62.  copier.addActionListener(new ActionListener() {
  63.          public void actionPerformed(ActionEvent e) {
  64.          
  65.          }
  66.  });
  67.  couper.addActionListener(new ActionListener() {
  68.          public void actionPerformed(ActionEvent e) {
  69.            
  70.          }
  71.  });
  72.  coller.addActionListener(new ActionListener() {
  73.          public void actionPerformed(ActionEvent e) {
  74.            
  75.          }
  76.  });
  77.  enregistrer.addActionListener(new ActionListener() {
  78.          public void actionPerformed(ActionEvent e) {
  79.            
  80.          }
  81.  });
  82.  f.setJMenuBar(barre);
  83.  f.setBackground(Color.LIGHT_GRAY);
  84.  f.pack();
  85.  f.setVisible(true);
  86.  f.setSize( 320,500);
  87.  f.setLocationRelativeTo(null);
  88.  f.setLayout(new GridLayout(5,1));
  89.  //f.setDefaultCloseOperation(EXIT_ON_CLOSE);
  90.               /* SCAN */
  91.  l1=new Label("Port Scanner",Label.CENTER);
  92.  l1.setForeground(Color.red);
  93.  l1.setFont(new Font("TimesRoman",Font.BOLD,25));
  94.  f.add(l1);
  95.  Panel p1=new Panel(new GridLayout(3,3));
  96.  host=new Label("Adresse IP :" );
  97.  host.setForeground(Color.blue);
  98.  host.setFont(new Font("TimesRoman",Font.BOLD,15));
  99.  p1.add(host);
  100.  hostName=new TextField(15);
  101.  p1.add(hostName);
  102.  from=new Label("Port Début:" );
  103.  from.setForeground(Color.blue);
  104.  from.setFont(new Font("TimesRoman",Font.BOLD,15));
  105.  p1.add(from);
  106.  fromPort=new TextField(15);
  107.  p1.add(fromPort);
  108.  to=new Label("Port Fin:" );
  109.  to.setForeground(Color.blue);
  110.  to.setFont(new Font("TimesRoman",Font.BOLD,15));
  111.  p1.add(to);
  112.  toPort=new TextField(15);
  113.  p1.add(toPort);
  114.  f.add(p1);
  115.  Panel p2=new Panel();
  116.  scan=new Button("Scan" );
  117.  scan.addActionListener(new ActionListener(){
  118.   public void actionPerformed(ActionEvent r){
  119.     if(hostName.getText().equals("" )){
  120.       JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS" );
  121.       return;}
  122.     else if (fromPort.getText().equals("" )){
  123.       JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS" );
  124.       return;}
  125.     else if(toPort.getText().equals("" )){
  126.       JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS" );
  127.       return;}
  128.     close=false;
  129.     Thread run1=new Thread(){
  130.      public void run(){
  131.       scan.setEnabled(false);
  132.       reset.setLabel("Stop" );
  133.       log.setText("" );
  134.       log.repaint();
  135.       h=hostName.getText();
  136.       fp=Integer.parseInt(fromPort.getText());
  137.       tp=Integer.parseInt(toPort.getText());
  138.       for(int i=fp;i<=tp;i++){
  139.        label.setText("Port "+i+" en cour de test..." );
  140.        if(close)
  141.         break;
  142.        try{
  143.         s=new Socket(h,i);
  144.         log.append("Port "+i+" est ouvert."+"\n" );
  145.         log.repaint();
  146.         s.close();
  147.         }
  148.        catch(Exception er){
  149.         continue;}
  150.       }
  151.       scan.setEnabled(true);
  152.       reset.setLabel("Reset" );
  153.       label.setText("Press Scan to start." );
  154.      }
  155.     };
  156.     run1.start();
  157.   }
  158.  });
  159.  reset=new Button("Reset" );
  160.  reset.addActionListener(new ActionListener(){
  161.   public void actionPerformed(ActionEvent t){
  162.    Thread run2=new Thread(){
  163.     public void run(){
  164.      close=true;
  165.      hostName.setText("" );
  166.      fromPort.setText("" );
  167.      toPort.setText("" );
  168.     }
  169.    };
  170.    run2.start();
  171.   }
  172.  });
  173.  Label empty=new Label();
  174.  p2.add(scan);
  175.  p2.add(empty);
  176.  p2.add(reset);
  177.  f.add(p2);
  178.  log=new TextArea();
  179.  f.add(log);
  180.  label=new Label("Cliquez sur Scan." );
  181.  label.setForeground(Color.blue);
  182.  f.add(label);
  183.  f.repaint();
  184.  f.setResizable(false);
  185.  /*f.addWindowListener(new WindowAdapter(){
  186.   public void windowClosing(WindowEvent e){
  187.    System.exit(1);
  188.   }
  189.  });*/
  190. }
  191. }


 
 
 
 
 
 
 
 

Code :
  1. package GUI;
  2. import java.util.ArrayList;
  3. import javax.swing.JOptionPane;
  4. import javax.swing.table.DefaultTableModel;
  5. import lanscanner.CommandLine;
  6. import lanscanner.IpObject;
  7. import lanscanner.PortScanner;
  8. import lanscanner.ScannerClass;
  9. public class MainFrame extends javax.swing.JFrame {
  10.     public ArrayList<IpObject> scanList;
  11.     DefaultTableModel tbmdl;
  12.     public int flag, state;
  13.     ScannerClass scan;
  14.     String fromIP, toIP;
  15.     String currentIP;
  16.     CommandLine command = new CommandLine();
  17.  
  18.     public MainFrame() {
  19.         initComponents();
  20.         tbmdl = new DefaultTableModel(new Object[][]{}, new String[]{"IP Adress", "Host Name", "MAC Adress"});
  21.         scanResultList.setModel(tbmdl);
  22.         state = 0;
  23.     }
  24.     @SuppressWarnings("unchecked" )
  25.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  26.     private void initComponents() {
  27.         rangeToolBar = new javax.swing.JToolBar();
  28.         jPanel1 = new javax.swing.JPanel();
  29.         jLabel1 = new javax.swing.JLabel();
  30.         jLabel2 = new javax.swing.JLabel();
  31.         startButton = new javax.swing.JButton();
  32.         statusLabel = new javax.swing.JLabel();
  33.         fromField = new javax.swing.JTextField();
  34.         toField = new javax.swing.JTextField();
  35.         stopButton = new javax.swing.JButton();
  36.         pingButton = new javax.swing.JButton();
  37.         new javax.swing.JToolBar();
  38.         new javax.swing.JPanel();
  39.         new javax.swing.JProgressBar();
  40.         new javax.swing.JLabel();
  41.         new javax.swing.JLabel();
  42.         new javax.swing.JLabel();
  43.        // devicesLabel = new javax.swing.JLabel();
  44.         scanResultPanel = new javax.swing.JPanel();
  45.        deviceListScrollPane = new javax.swing.JScrollPane();
  46.         scanResultList = new javax.swing.JTable();
  47.         //sharedFoldersPanel = new javax.swing.JPanel();
  48.         //folderListScrollPane = new javax.swing.JScrollPane();
  49.         //sharedFoldersList = new javax.swing.JList();
  50.         //sharedButton = new javax.swing.JButton();
  51.        // onlineButton = new javax.swing.JButton();
  52.         jMenuBar1 = new javax.swing.JMenuBar();
  53.         fileMenu = new javax.swing.JMenu();
  54.         exitMenuItem = new javax.swing.JMenuItem();
  55.         helpMenu = new javax.swing.JMenu();
  56.         helpMenuItem = new javax.swing.JMenuItem();
  57.         aboutMenuItem = new javax.swing.JMenuItem();
  58.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  59.         setTitle("Scanner Résaux" );
  60.         setLocationByPlatform(true);
  61.         rangeToolBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  62.         rangeToolBar.setRollover(true);
  63.         jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  64.         jLabel1.setText("Adresse ip de début :" );
  65.         jLabel2.setText("Adresse ip de fin :" );
  66.         startButton.setForeground(new java.awt.Color(0, 102, 0));
  67.         startButton.setText("Scan" );
  68.         startButton.setToolTipText("Cliquez pour démarrer le Scan" );
  69.         startButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  70.         startButton.addActionListener(new java.awt.event.ActionListener() {
  71.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  72.                 startButtonActionPerformed(evt);
  73.             }
  74.         });
  75.        
  76.         fromField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
  77.         fromField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  78.         fromField.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
  79.         fromField.addKeyListener(new java.awt.event.KeyAdapter() {
  80.             public void keyTyped(java.awt.event.KeyEvent evt) {
  81.                 fromFieldKeyTyped(evt);
  82.             }
  83.         });
  84.         toField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
  85.         toField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  86.         toField.addKeyListener(new java.awt.event.KeyAdapter() {
  87.             public void keyTyped(java.awt.event.KeyEvent evt) {
  88.                 toFieldKeyTyped(evt);
  89.             }
  90.         });
  91.         stopButton.setForeground(new java.awt.Color(204, 0, 0));
  92.         stopButton.setText("Stop Scan" );
  93.         stopButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  94.         stopButton.setEnabled(false);
  95.         stopButton.addActionListener(new java.awt.event.ActionListener() {
  96.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  97.                 stopButtonActionPerformed(evt);
  98.             }
  99.         });
  100.         pingButton.setText("Scan port" );
  101.         //pingButton.setText("Ping" );
  102.         pingButton.setEnabled(false);
  103.        
  104.    
  105.        
  106.         pingButton.addActionListener(new java.awt.event.ActionListener() {
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  108.                 pingButtonActionPerformed(evt);
  109.                        
  110.             }
  111.         });
  112.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  113.         jPanel1.setLayout(jPanel1Layout);
  114.         jPanel1Layout.setHorizontalGroup(
  115.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  116.             .addGroup(jPanel1Layout.createSequentialGroup()
  117.                 .addContainerGap()
  118.                 .addComponent(jLabel1)
  119.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  120.                 .addComponent(fromField, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
  121.                 .addGap(18, 18, 18)
  122.                 .addComponent(jLabel2)
  123.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  124.                 .addComponent(toField, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
  125.                 .addGap(39, 39, 39)
  126.                 .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
  127.                 .addGap(18, 18, 18)
  128.                 .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
  129.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  130.                 .addComponent(pingButton, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
  131.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
  132.                 .addComponent(statusLabel)
  133.                 .addContainerGap())
  134.         );
  135.         jPanel1Layout.setVerticalGroup(
  136.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  137.             .addGroup(jPanel1Layout.createSequentialGroup()
  138.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  139.                     .addGroup(jPanel1Layout.createSequentialGroup()
  140.                         .addContainerGap()
  141.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  142.                             .addComponent(startButton)
  143.                             .addComponent(stopButton)
  144.                             .addComponent(pingButton)
  145.                             .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
  146.                     .addGroup(javax.swing.GroupLayout.Alignment.CENTER, jPanel1Layout.createSequentialGroup()
  147.                         .addGap(14, 14, 14)
  148.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  149.                             .addComponent(fromField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  150.                             .addComponent(jLabel1)))
  151.                     .addGroup(javax.swing.GroupLayout.Alignment.CENTER, jPanel1Layout.createSequentialGroup()
  152.                         .addGap(14, 14, 14)
  153.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  154.                             .addComponent(toField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  155.                             .addComponent(jLabel2))))
  156.                 .addContainerGap())
  157.         );
  158.         rangeToolBar.add(jPanel1);
  159.      
  160.         scanResultPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Device List:", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));
  161.         scanResultList.setFont(new java.awt.Font("Tahoma", 1, 12));
  162.         scanResultList.setModel(new javax.swing.table.DefaultTableModel(
  163.             new Object [][] {
  164.                 {null, null, null},
  165.                 {null, null, null},
  166.                 {null, null, null},
  167.                 {null, null, null},
  168.                 {null, null, null},
  169.                 {null, null, null},
  170.                 {null, null, null},
  171.                 {null, null, null},
  172.                 {null, null, null},
  173.                 {null, null, null},
  174.                 {null, null, null},
  175.                 {null, null, null},
  176.                 {null, null, null},
  177.                 {null, null, null},
  178.                 {null, null, null},
  179.                 {null, null, null},
  180.                 {null, null, null},
  181.                 {null, null, null},
  182.                 {null, null, null},
  183.                 {null, null, null},
  184.                 {null, null, null},
  185.                 {null, null, null},
  186.                 {null, null, null},
  187.                 {null, null, null},
  188.                 {null, null, null},
  189.                 {null, null, null}
  190.             },
  191.             new String [] {
  192.                 "IP Adress", "Host Name", "MAC Adress"
  193.             }
  194.         ) {
  195.             boolean[] canEdit = new boolean [] {
  196.                 false, false , false
  197.             };
  198.             public boolean isCellEditable(int rowIndex, int columnIndex) {
  199.                 return canEdit [columnIndex];
  200.             }
  201.         });
  202.         scanResultList.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  203.         scanResultList.setGridColor(new java.awt.Color(255, 255, 255));
  204.         scanResultList.addMouseListener(new java.awt.event.MouseAdapter() {
  205.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  206.                 scanResultListMouseClicked(evt);
  207.             }
  208.         });
  209.        deviceListScrollPane.setViewportView(scanResultList);
  210.         javax.swing.GroupLayout scanResultPanelLayout = new javax.swing.GroupLayout(scanResultPanel);
  211.         scanResultPanel.setLayout(scanResultPanelLayout);
  212.         scanResultPanelLayout.setHorizontalGroup(
  213.             scanResultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  214.             .addComponent(deviceListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
  215.         );
  216.         scanResultPanelLayout.setVerticalGroup(
  217.             scanResultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  218.             .addComponent(deviceListScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
  219.         );
  220.      
  221.      
  222.         fileMenu.setText("File" );
  223.         exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
  224.         exitMenuItem.setText("Exit" );
  225.         exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
  226.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  227.                 exitMenuItemActionPerformed(evt);
  228.             }
  229.         });
  230.         fileMenu.add(exitMenuItem);
  231.         jMenuBar1.add(fileMenu);
  232.         helpMenu.setText("Help" );
  233.         helpMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.ALT_MASK));
  234.         helpMenuItem.setText("Help" );
  235.         helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
  236.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  237.                 helpMenuItemActionPerformed(evt);
  238.             }
  239.         });
  240.         helpMenu.add(helpMenuItem);
  241.         aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
  242.         aboutMenuItem.setText("About" );
  243.         aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
  244.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  245.                 aboutMenuItemActionPerformed(evt);
  246.             }
  247.         });
  248.         helpMenu.add(aboutMenuItem);
  249.         jMenuBar1.add(helpMenu);
  250.         setJMenuBar(jMenuBar1);
  251.        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  252.         getContentPane().setLayout(layout);
  253.        
  254.         layout.setHorizontalGroup(
  255.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  256.             .addComponent(rangeToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
  257.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  258.                 .addComponent(scanResultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  259.                   .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  260.                            )) );
  261.        
  262.         layout.setVerticalGroup(
  263.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  264.             .addGroup(layout.createSequentialGroup()
  265.                 .addComponent(rangeToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
  266.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  267.                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  268.                     .addComponent(scanResultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  269.                         )) );
  270.         pack();
  271.     }// </editor-fold>//GEN-END:initComponents
  272.     private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
  273.         // TODO add your handling code here:
  274.         System.exit(1);
  275.     }//GEN-LAST:event_exitMenuItemActionPerformed
  276.     private void helpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuItemActionPerformed
  277.         // TODO add your handling code here:
  278.         HelpFrame hf = new HelpFrame();
  279.         hf.setLocationRelativeTo(null);
  280.         hf.setVisible(true);
  281.     }//GEN-LAST:event_helpMenuItemActionPerformed
  282.     private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
  283.         // TODO add your handling code here:
  284.         AboutFrame af = new AboutFrame();
  285.         af.setLocationRelativeTo(null);
  286.         af.setVisible(true);
  287.     }//GEN-LAST:event_aboutMenuItemActionPerformed
  288.     private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
  289.         // TODO add your handling code here:
  290.         if (fromField.getText().isEmpty()) {
  291.             JOptionPane.showMessageDialog(null, "Veuillez entrer une adresse IP de début" );
  292.             return;
  293.         }
  294.         if (toField.getText().isEmpty()) {
  295.             JOptionPane.showMessageDialog(null, "Veuillez entrer une adresse IP de fin" );
  296.             return;
  297.         }
  298.         startButton.setText("Scanning" );
  299.         startButton.setEnabled(false);
  300.         stopButton.setEnabled(true);
  301.         scanResultList.clearSelection();
  302.      
  303.         //lowerStatusLabel.setText("Scanning" );
  304.        
  305.         state = flag = 0;
  306.         tbmdl.setRowCount(0);
  307.         scanList = new ArrayList<IpObject>();
  308.        // sharedDevices = new ArrayList<IpObject>();
  309.         fromIP = fromField.getText();
  310.         toIP = toField.getText();
  311.         String[] initialIP = fromIP.split("\\." );
  312.         String[] finalIP = toIP.split("\\." );
  313.         this.scan = new ScannerClass(initialIP, finalIP, this);
  314.     }
  315.     private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
  316.         state = 1;
  317.         startButton.setText("Start Scan" );
  318.         startButton.setEnabled(true);
  319.         stopButton.setEnabled(false);
  320.        
  321.     }
  322.     private void scanResultListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_scanResultListMouseClicked
  323.         // TODO add your handling code here:
  324.         if (evt.getClickCount() == 1) {
  325.             pingButton.setEnabled(true);
  326.             int row = scanResultList.rowAtPoint(evt.getPoint());
  327.             String selectedIP = scanResultList.getValueAt(row, 0).toString();
  328.             currentIP = selectedIP;
  329.             pingButton.setEnabled(true);
  330.            
  331.         }
  332.        
  333.     }
  334.     private void fromFieldKeyTyped(java.awt.event.KeyEvent evt) {
  335.         // TODO add your handling code here:
  336.         char c = evt.getKeyChar();
  337.         if (c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == '0' || c == '.' || c == evt.VK_BACK_SPACE) {
  338.         } else {
  339.             evt.consume();
  340.         }
  341.     }
  342.     private void toFieldKeyTyped(java.awt.event.KeyEvent evt) {
  343.         // TODO add your handling code here:
  344.         char c = evt.getKeyChar();
  345.         if (c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == '0' || c == '.' || c == evt.VK_BACK_SPACE) {
  346.         } else {
  347.             evt.consume();
  348.         }
  349.     }
  350.     private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {
  351.         // TODO add your handling code here:
  352.    
  353.       new PortScanner();
  354.    
  355.         }
  356.     public static void main(String args[]) {
  357.         java.awt.EventQueue.invokeLater(new Runnable() {
  358.             public void run() {
  359.                 MainFrame mf = new MainFrame();
  360.                 mf.setLocationRelativeTo(null);
  361.                 mf.setVisible(true);
  362.             }
  363.         });
  364.     }
  365.     // Variables declaration - do not modify//GEN-BEGIN:variables
  366.     private javax.swing.JMenuItem aboutMenuItem;
  367.     private javax.swing.JScrollPane deviceListScrollPane;
  368.     private javax.swing.JMenuItem exitMenuItem;
  369.     private javax.swing.JMenu fileMenu;
  370.     private javax.swing.JTextField fromField;
  371.     private javax.swing.JMenu helpMenu;
  372.     private javax.swing.JMenuItem helpMenuItem;
  373.     private javax.swing.JLabel jLabel1;
  374.     private javax.swing.JLabel jLabel2;
  375.     private javax.swing.JMenuBar jMenuBar1;
  376.     private javax.swing.JPanel jPanel1;
  377.     private javax.swing.JButton pingButton;
  378.     private javax.swing.JToolBar rangeToolBar;
  379.     private javax.swing.JTable scanResultList;
  380.     private javax.swing.JPanel scanResultPanel;
  381.     private javax.swing.JButton startButton;
  382.     private javax.swing.JLabel statusLabel;
  383.     private javax.swing.JButton stopButton;
  384.     private javax.swing.JTextField toField;
  385.     // End of variables declaration//GEN-END:variables
  386.     public void insertObj(IpObject obj) {
  387.         int i = scanResultList.getRowCount();
  388.         tbmdl.addRow(new Object[]{});
  389.         scanResultList.setValueAt(obj.getIpAdress(), i, 0);
  390.         scanResultList.setValueAt(obj.getHostName(), i, 1);
  391.         scanResultList.setValueAt(obj.getMacAdress(), i, 2);
  392.      
  393.     }
  394.  
  395. }


 
image des interfaces pour mieux comprendre mes problèmes : http://www.mediafire.com/?zncpbzii7d4e2jk
 
merciii d'avance

mood
Publicité
Posté le 29-04-2013 à 02:53:53  profilanswer
 

n°2187973
chimo01
Posté le 29-04-2013 à 12:35:16  profilanswer
 

up  :(


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

  scan réseau+scan de port

 

Sujets relatifs
Aide pour la création d'un fichier bat pour ping sur réseau[Résolu][VBScript] Voir si l'on accède à un répertoire réseau
Alias EasyPHP sur lecteur réseaudéplacement fichier sur lecteur réseau
envoyer des donnes sur un reseauUSB problème port série virtuel windows
php et accès a partage reseau (WS2012E)Enregistrement en PDF sur réseau
[C/Reseau] proxy FTP (simple) en C[C/Reseau] Connaitre le port Client connecté au port 21 du FTP
Plus de sujets relatifs à : scan réseau+scan de port


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR