rendered paste bodyimport java.net.*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * Summary description for gui * */public class gui extends JFrame{ // Variables declaration private JTextPane jTextPane1; private JScrollPane jScrollPane1; private JButton Scan; private JButton IPset; private JPanel contentPane; // End of variables declaration public gui() { super(); initializeComponent(); // // TODO: Add any constructor code after initializeComponent call // this.setVisible(true); } /** * 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 Windows Form Designer. Otherwise, retrieving design might not work properly. * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder * to retrieve your design properly in future, before revising this method. */ private void initializeComponent() { jTextPane1 = new JTextPane(); jScrollPane1 = new JScrollPane(); Scan = new JButton(); IPset = new JButton(); contentPane = (JPanel)this.getContentPane(); // // jTextPane1 // // // jScrollPane1 // jScrollPane1.setViewportView(jTextPane1); // // Scan // Scan.setText("Scan..."); Scan.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Scan_actionPerformed(e); } }); // // IPset // IPset.setText("Set IP"); IPset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { IPset_actionPerformed(e); } }); // // contentPane // contentPane.setLayout(null); addComponent(contentPane, jScrollPane1, 17,54,600,384); addComponent(contentPane, Scan, 17,16,83,28); addComponent(contentPane, IPset, 111,16,83,28); // // gui // this.setTitle("Network Monitor"); this.setLocation(new Point(106, 27)); this.setSize(new Dimension(640, 480)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } /** Add Component Without a Layout Manager (Absolute Positioning) */ private void addComponent(Container container,Component c,int x,int y,int width,int height) { c.setBounds(x,y,width,height); container.add(c); } // // TODO: Add any appropriate code in the following Event Handling Methods // private void Scan_actionPerformed(ActionEvent e) { System.out.println("\nScan button clicked."); // TODO: Add any handling code here } public void IPset_actionPerformed(ActionEvent e) { System.out.println("\nIP address button clicked."); // TODO: Add any handling code here String IP = JOptionPane.showInputDialog("Enter IP address (e.g. 148.197.27.):"); System.out.println("IP address set to "+IP+"x"); JOptionPane.showMessageDialog( null, "IP address set to "+IP+"x"); } // // TODO: Add any method code to meet your needs in the following area //static int ip2=0;public static void scan(String args[]) throws IOException { String array[][] = new String[254][2]; // array to store scan results for each IP int counter=0; // declare counter for array writing while(ip2<254) // while loop to iterate IP connection { try { TimedSocket ts = new TimedSocket(); // create instance of TimedSocket class Socket s1; // socket creation InputStream s1In; DataInputStream dis; String info; // variables for successful connection info store String info2; String ip=ipgen(); // run IP generation method System.out.print("Trying: "+ip); s1 = new Socket(); // socket creation s1 = ts.getSocket(ip, 5432, 600); // pass connection host, socket and delay timeout to external class s1In = s1.getInputStream(); dis = new DataInputStream(s1In); info = s1.getInetAddress().getHostName(); //gives host address for printing info2 = s1.getInetAddress().getHostAddress(); //gives IP for printing array[counter][0] = s1.getInetAddress().getHostName(); // gives host for array array[counter][1] = s1.getInetAddress().getHostAddress(); // gives IP for array String st = new String(dis.readUTF( )); System.out.println(); System.out.println(info); // added IP print System.out.println(info2); //System.out.println("The 1st entries on the array are: "+array[counter][0]+" and "+array[counter][1]); counter++; // increments counter for array storage dis.close(); s1In.close(); s1.close(); } catch(ConnectException e) // Connection exception clause { System.out.print(" error! "+e.getMessage()); } catch(Exception e) { System.out.print(" Exception caught "+e.getMessage()); // exception clause } finally { System.out.println(); } }}public static String ipgen(String str) // method for IP generation between x.x.x.1 and x.x.x.254 { String IP = "148.197.27."; //IPset_actionPerformed.IP if (ip2 < 254) { ip2++; } return IP+ip2; }public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading L&F: "); System.out.println(ex); } catch(IoException ex) { // do whatever } new gui(); }//= End of Testing =}