I have been working on a program that Should Scan a small Subnet i.e for eg 10.1.1.1 to 10.1.1.255 with the subnet mask 255.255.255.0
I am attaching screenshots of the main screen of my project as "Screenshot 1" source code :jMenu.java
I am posting the code here:
package projectpack;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
public class jMenu extends JFrame implements ActionListener
{
JFrame jf;
JPanel jp;
JScrollPane pane;
Container c1;
JTable table;
JLabel l;
JLabel l2;
JLabel lbl5;
JLabel l3;
JLabel lbl2;
JTextField jt;
JTextField jt2;
JButton b1;
JButton b2;
String lbl;
JButton b3;
String lb2;
JButton b4;
JButton b5;
JMenu f;
JMenuItem it1,it2,it3,it4,it5,it6,it7,it8,it9,it10,it11,it12 ;
JMenu m1,m2,m3,m4,m5;
JMenuBar bar;
public jMenu()
{
String str="Network Watcher v2";
jf=new JFrame(str);
jp = new JPanel();//panel
c1=jf.getContentPane();
l=new JLabel("Hostname");
l2=new JLabel("IP"); //label ip
jt=new JTextField(16); //text box host
jt2=new JTextField(16); //textbox 2 IP
b1=new JButton("Look Up"); //button 1 checking IP address
b2=new JButton("Mobile"); //button 1 checking IP address
lbl = "<html>" + "Desktop" + "<br>" + " "+"View" + "</html>";
b3=new JButton(lbl); //button 1 checking IP address
lb2 = "<html>" + "File" + "<br>" + " "+"Transfer" + "</html>";
b4=new JButton(lb2); //button 1 checking IP address
b5=new JButton("Scan");
JMenu f=new JMenu(); //menu
it1=new JMenuItem("Export all");
it2=new JMenuItem("Export Selection");
it3=new JMenuItem("Exit");
it4=new JMenuItem("Next Alive Host");
it5=new JMenuItem("Next Open Port");
it6=new JMenuItem("Show Details");
it7=new JMenuItem("Rescan IP");
it8=new JMenuItem("Delete IP");
it9=new JMenuItem("Preferences");
it10=new JMenuItem("Fetchers");
it11=new JMenuItem("About");
it12=new JMenuItem("Getting Started");
m1=new JMenu("File");
m2=new JMenu("GOTO");
m3=new JMenu("Commands");
m4=new JMenu("Tools");
m5=new JMenu("Help");
bar=new JMenuBar();
b5.addActionListener(this);
c1.setLayout(null);
jp.setBounds(0,0,1200,296);
Color colorlightgreen=new Color(242,248,252);
jp.setBackground(colorlightgreen);
//+++++++++++++++++++++++TABLE and Table DATA++++++++++++++++++++++++++++++++++++++++++++++++
String data[][] = {{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
{"", "", "",""},
};
String fields[] = {"IP", "HOST", "PORTS","WEBDETECT"};
table = new JTable( data, fields );
pane = new JScrollPane( table );
pane.setBounds(0,300,1015,400);
//+++++++++++++++++++++++labels and texts++++++++++++++++++++++++++++++++++++++++++++++++++
l.setBounds(0,45,200,100);//positions a component onto the screen
l2.setBounds(0,85,200,100);
l3=new JLabel("===========================================================================================================================================================================================================");
l3.setBounds(0,260,1100,40);//positions a component onto the screen
jt.setBounds(65,85,70,22);
jt2.setBounds(65,120,70,22);
//++++++++++++++++++++++Buttons++++++++++++++++++++++++++++++++++++++++++++++++++++
b1.setBounds(170,95,85,35);
b2.setBounds(500,60,100,100);
b3.setBounds(700,60,100,100);
b4.setBounds(900,60,100,100);
b5.addActionListener(this);
b5.setBounds(300,60,100,100);
jp.add(b5);
//++++++++++++++++++++++++++++++Menu and Menu Items+++++++++++++++++++++++++++++++++++++++++++
m1.add(it1);
m1.add(it2);
m1.add(it3);
m2.add(it4);
m2.add(it5);
m3.add(it6);
m3.add(it7);
m3.add(it8);
m4.add(it9);
m4.add(it10);
m5.add(it11);
m5.add(it12);
bar.add(m1);
bar.add(m2);
bar.add(m3);
bar.add(m4);
bar.add(m5);
bar.setBorderPainted(false);
bar.setBounds(0,0,1100,30);
bar.setBackground(colorlightgreen);
//++++++++++++++++++++++++++++++++++++Adding components onto panels++++++++++++++++++++++++++++++++++
jp.add(l);
jp.add(l2);//jp.add(l3);
jp.add(bar);
jp.add(jt);
jp.add(jt2);
jp.add(b1);
jp.add(b2);
jp.add(b3);
jp.add(b4);
//jp.add(b5);
jp.setLayout(null);
c1.add(jp);
c1.add(pane);
jf.show();
jf.setSize(new Dimension(1024,768));
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
jMenu jj=new jMenu();
//++++++++++++++++++++++++++++++Frame Container and panel+++++++++++++++++++++++++++++++++++++
}
public void wait4scan()
{
IpPingmod startPing=new IpPingmod();
startPing.gen_ip();
startPing.xxx();
while(IpPingmod.scan_fin==false)
{
}
}
public void actionPerformed(ActionEvent ae){
{
if(ae.getSource()==b5)
{
ImageIcon icon=new ImageIcon("D:\\ProjectP\\images\\SCANNING_23235.gif");
lbl2=new JLabel();
lbl2.setIcon(icon);
lbl2.setBounds(0,200,1200,100);
jp.add(lbl2);
jp.updateUI();
b1.setEnabled(false);
b2.setEnabled(false);
b3.setEnabled(false);
b4.setEnabled(false);
b5.setEnabled(false);
table.setEnabled(false);
bar.setEnabled(false);
m1.setEnabled(false);
m2.setEnabled(false);
m3.setEnabled(false);
m4.setEnabled(false);
m5.setEnabled(false);
jt.setEnabled(false);
jt2.setEnabled(false);
jp.updateUI();
//this.wait4scan();
}
};
}}
There is an another source code file which i have created in the same package that will do the work for me,it contains 25 classes each will then be a thread,out of which 1st 24 will scan 10 hosts in the subnet,and the last class wil scan 15 remaining hosts in a 255 host subnet.I am using the windows command Ping to scan the hosts,ICMP PING,
((Process p1 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j]=p1.waitFor(); // wait for returns 0 if alive otherwise 1))
for eg if the subnet is 10.40.104
class "Ping1" will scan hosts from 10.40.104.1 to 10.40.104.10
class "Ping2" will scan hosts from 10.40.104.11 to 10.40.104.20
and so on....till Ping25
I am posting the code file named "IpPingmod.java" here
package projectpack;
import java.io.*;
import java.net.*;
import java.awt.*;
public class IpPingmod extends Thread
{
public static boolean scan_fin=false;
public static String ipAdd[]=new String[256];
public static volatile String subnet;
public static volatile int status[]=new int[256];
public static String[] aliveIp=new String[256];
public static String[] aliveIp2=new String[256];
public IpPingmod()
{
try{
InetAddress ia=InetAddress.getLocalHost();
String Ip=ia.getHostAddress();
int occ_of_dot=Ip.lastIndexOf(".");
subnet=Ip.substring(0,occ_of_dot);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void xxx()
{
Ping1 one=new Ping1();Ping2 two=new Ping2();Ping3 three=new Ping3();Ping4 four=new Ping4();Ping5 five=new Ping5();Ping6 six=new Ping6();Ping7 seven=new Ping7();Ping8 eight=new Ping8();Ping9 nine=new Ping9();Ping10 ten=new Ping10();Ping11 eleven=new Ping11();Ping12 twelve=new Ping12();Ping13 thirteen=new Ping13();Ping14 fourteen=new Ping14();Ping15 fifteen=new Ping15();Ping16 sixteen=new Ping16();Ping17 seventeen=new Ping17();Ping18 eighteen=new Ping18();Ping19 nineteen=new Ping19();Ping20 twenty=new Ping20();Ping21 twentyone=new Ping21();Ping22 twentytwo=new Ping22();Ping23 twentythree=new Ping23();Ping24 twentyfour=new Ping24();Ping25 twentyfive=new Ping25();
one.start();two.start();three.start();four.start();five.start();six.start();seven.start();eight.start();nine.start();ten.start();eleven.start();twelve.start();thirteen.start();fourteen.start();fifteen.start();sixteen.start();seventeen.start();eighteen.start();nineteen.start();twenty.start();twentyone.start();twentytwo.start();twentythree.start();twentyfour.start();twentyfive.start();
}
public void gen_ip()
{
ipAdd[0]=subnet+"."+"0";
for(int i=1;i<=255;i++)
{
ipAdd[i]=subnet+"."+i;
}
}
}
class Ping1 extends Thread
{
public synchronized void run()
{
for(int j=0;j<11;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p1 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j]=p1.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping2 extends Thread
{
public synchronized void run()
{
for(int j=11;j<21;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p2 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j]= p2.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
class Ping3 extends Thread
{
public synchronized void run()
{
for(int j=21;j<31;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p3 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j]=p3.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class3 ends
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping4 extends Thread
{
public synchronized void run()
{
for(int j=31;j<41;j++)
{
try
{
this.sleep((long)(Math.random() * 100));
Process p4 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p4.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping5 extends Thread
{
public synchronized void run()
{
for(int j=41;j<51;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p5 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p5.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping6 extends Thread
{
public synchronized void run()
{
for(int j=51;j<61;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p6 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p6.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 6 ends
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping7 extends Thread
{
public synchronized void run()
{
for(int j=61;j<71;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p7 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p7.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 7 ends
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping8 extends Thread
{
public synchronized void run()
{
for(int j=71;j<81;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p8 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p8.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 8 ends
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping9 extends Thread
{
public synchronized void run()
{
for(int j=81;j<91;j++)
{
try{
this.sleep((long)(Math.random() * 100));
Process p9 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p9.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 9 ends
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Ping10 extends Thread
{
public synchronized void run()
{
for(int j=91;j<101;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p10 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p10.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 10 ends
class Ping11 extends Thread
{
public synchronized void run()
{
for(int j=101;j<111;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p11 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p11.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 11 ends
class Ping12 extends Thread
{
public synchronized void run()
{
for(int j=111;j<121;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p12 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p12.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 12 ends
class Ping13 extends Thread
{
public synchronized void run()
{
for(int j=121;j<131;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p13 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p13.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 13 ends
class Ping14 extends Thread
{
public synchronized void run()
{
for(int j=131;j<141;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p14 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p14.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 14 ends
class Ping15 extends Thread
{
public synchronized void run()
{
for(int j=141;j<151;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p15 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p15.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 15 ends
class Ping16 extends Thread
{
public synchronized void run()
{
for(int j=151;j<161;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p16 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p16.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 16 ends
class Ping17 extends Thread
{
public synchronized void run()
{
for(int j=161;j<171;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p17 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p17.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 17 ends
class Ping18 extends Thread
{
public synchronized void run()
{
for(int j=171;j<181;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p18 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p18.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 18 ends
class Ping19 extends Thread
{
public synchronized void run()
{
for(int j=181;j<191;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p19 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p19.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 19 ends
class Ping20 extends Thread
{
public synchronized void run()
{
for(int j=191;j<201;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p20 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p20.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 20 ends
class Ping21 extends Thread
{
public synchronized void run()
{
for(int j=201;j<211;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p21 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p21.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 21 ends
class Ping22 extends Thread
{
public synchronized void run()
{
for(int j=211;j<221;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p22 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p22.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 22ends
class Ping23 extends Thread
{
public synchronized void run()
{
for(int j=221;j<231;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p23 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p23.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 23 ends
class Ping24 extends Thread
{
public synchronized void run()
{
for(int j=231;j<241;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p24 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p24.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
}
}
//class 24 ends
class Ping25 extends Thread
{
public static boolean beep=false;
public synchronized void run()
{
for(int j=241;j<256;j++)
{
try{
this.sleep((long)(Math.random() * 10));
Process p25 = Runtime.getRuntime().exec("ping -n 1 " +IpPingmod.ipAdd[j]);
IpPingmod.status[j] = p25.waitFor(); // wait for returns 0 if alive otherwise 1
//System.out.println(IpPingmod.ipAdd[j] + " is " + (IpPingmod.status[j]==0 ? "alive" : "dead"));
}catch(Exception e)
{
System.out.println(e);
}
}
for(int i=0;i<256;i++)
{
if(IpPingmod.status[i]==0)
IpPingmod.aliveIp[i]=IpPingmod.ipAdd[i];
else
IpPingmod.aliveIp[i]="not alive";
}
for(int i=0;i<256;i++)
{
if(!(IpPingmod.aliveIp[i].equals("not alive")))
{
IpPingmod.aliveIp2[i]=IpPingmod.aliveIp[i];//now aliveIp2 contains the list of IP addresses which are alive;
System.out.println(IpPingmod.aliveIp2[i]);
}
}
try {
System.out.print ( "\007" );
System.out.flush();
Ping25.beep=true;
} catch (Exception e) {
e.printStackTrace();
}
if(Ping25.beep==true)
IpPingmod.scan_fin=true;
} //run completes
}
//class 25 ends
PROBLEM HERE:Now when i start the program jMenu from the command line,it starts off well with the UI in place...but
when i click the Scan Button
i can see various ping process in the background in the Windows Task manager and the java.exe process which takes 99% of the CPU all the time.
The BIG problem: computer stops responding at this time.may be because all the CPU is used by java.exe .
A BIG Surprise:when i run the IpPingmod.java program Using MAIN in the code and with some modifications and the logic being the same its works well does the job for me without using most of CPU.
I WANT A SOLUTION FOR THIS.SO THAT I CAN USE THE IpPingmod.java IN THE SAME PACKAGE AND USE IT FROM jMenu.java
Or please somebody help me with the IsReachable method of InetAddress for the whole subnet.
below are the screenshots for my program jMenu