PortScanner -with GUI

5 views
Skip to first unread message

nandu

unread,
Jan 1, 2007, 12:10:10 PM1/1/07
to Open Projects For All

import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border .*;
import java.awt.*;
import java.io.*;
import java.applet.*;
import javax.swing.JPopupMenu;
import javax.swing.border.BevelBorder;
import javax.swing.event.PopupMenuEvent;


class PortScanner1 extends JFrame

{ JButton check,cancel;
JTextField textfield1,textfield2,textfield3;
JTextArea output;
JScrollPane scrollpane;
JLabel label1,label2,label3;

PortScanner1()

{ setLayout(new FlowLayout()) ;
check = new JButton("Scan");

label1= new JLabel("Enter first PORT");
label1.setForeground(Color.white);
label2= new JLabel("Enter second PORT");
label2.setForeground(Color.white);
label3= new JLabel("Enter IP");
label3.setForeground(Color.white);
textfield1= new JTextField(10);
textfield2= new JTextField(10);
textfield3= new JTextField(10);
output = new JTextArea("\n",20,30);
output.setBackground(Color.yellow);
// output.setBorder(Border.MetalBorders.Flush3DBorder);
scrollpane = new JScrollPane(output);
add(label1);
add(textfield1);
add(label2);
add(textfield2);
add(label3);
add(textfield3);
add(check);
add(scrollpane);
getContentPane().setBackground(Color.black);


clickHandler obj = new clickHandler();

check.addActionListener(obj);
// cancel.addActionListener(obj);

}

private class clickHandler implements ActionListener
{

public void actionPerformed(ActionEvent eg)
{

if(eg.getSource()==check)
{ Runnable r = new myHandler();
Thread t = new Thread(r);
t.start();
}
if(eg.getSource()==cancel)
{
}

}
}


private class myHandler extends JApplet implements Runnable

{

int openport=0;

public void run()
{
boolean trueorfalse = true;
int startPort = Integer.parseInt(textfield1.getText());
int stopPort = Integer.parseInt(textfield2.getText());
String ipaddress = textfield3.getText();
//InetAddress obj = new InetAddress(ipaddress);


output.setText("TCP Open PORTS:\n\n");

int diff = stopPort-startPort;

//int data[] = new int[diff];
for( int i=startPort; i <=stopPort; i++)
{

if( i<= stopPort )

{ try
{
Socket ServerSok = new Socket(ipaddress,i);
//data[i]=i;
System.out.println("Working:");
output.append("\n");
output.append(""+i);
openport++;
ServerSok.close();
}

catch (Exception ef)
{
}


}
//output.append("\n"+i);

}

output.append("\n\n"+openport+" open ports on host " +
ipaddress);

}
}

}

public class PortScanner
{
public static void main(String args[])
{


PortScanner1 m1 = new PortScanner1();
m1.setSize(700,400);
m1.setVisible(true);
m1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}
}


/*


public static void main(String args[])
{
int startPortRange=0;
int stopPortRange=0;

startPortRange = Integer.parseInt(args[0]);
stopPortRange = Integer.parseInt(args[1]);


for(int i=startPortRange; i <=stopPortRange; i++)
{
try
{
Socket ServerSok = new
Socket("66.249.81.86",i);

System.out.println("Port in use: " + i );

ServerSok.close();
}
catch (Exception e)
{
}
System.out.println("Port not in use: " + i );
}
}
} */

nandu

unread,
Jan 1, 2007, 12:19:17 PM1/1/07
to Open Projects For All
In the above program,the user inputs two PORT numbers and suppplies the
IP address.The program then send packets to the IP and find out the
open ports using the response they get

Sincerely

Nandu

Reply all
Reply to author
Forward
0 new messages