Q.Write a program to scan ports of a system
Port Scanner Java Program:->
import java.net.*;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PScanner {
public static void main(String[] args) {
InetAddress ia=null;
String host=null;
try {
host=JOptionPane.showInputDialog("Enter
the Host name to scan:\n ");
if(host!=null){
ia =
InetAddress.getByName(host);
scan(ia); }
}
catch (UnknownHostException e) {
System.err.println(e );
}
System.out.println("The host name is invalid");
//System.exit(0);
}
public static void scan(final InetAddress remote) {
//variables for menu bar
int port=0;
String hostname = remote.getHostName();
for ( port = 0; port < 65536; port++) {
try {
Socket s = new
Socket(remote,port);
System.out.println("Server is listening
on port " + port+ " of " + hostname);
s.close();
} catch (IOException ex) {
// The remote host is not
listening on this port
System.out.println("Server is not
listening on port " + port+ " of " + hostname);
}
}//for ends
}
}
OUTPUT:->
C:\Program
Files\Java\jdk1.6.0_03\bin>javac PScanner.java
C:\Program Files\Java\jdk1.6.0_03\bin>java
PScanner
C:\Program Files\Java\jdk1.6.0_03\bin>java
PScanner
Server is not listening on port 0 of localhost
Server is not listening on port 1 of localhost
Server is not listening on port 2 of localhost
Server is not listening on port 3 of localhost
Server is not listening on port 4 of localhost
Server is not listening on port 5 of localhost
Server is not listening on port 6 of localhost
Server is not listening on port 7 of localhost
Server is not listening on port 8 of localhost
Server is not listening on port 9 of localhost
Server is not listening on port 10 of localhost
Server is not listening on port 11 of localhost
Server is not listening on port 12 of localhost
Server is not listening on port 13 of localhost
Server is not listening on port 14 of localhost
Server is not listening on port 15 of localhost
Server is not listening on port 16 of localhost
Server is not listening on port 17 of localhost
Server is not listening on port 18 of localhost
Server is not listening on port 19 of localhost
Server is not listening on port 20 of localhost
Server is not listening on port 21 of localhost
Server is not listening on port 22 of localhost
Server is not listening on port 23 of localhost
Server is not listening on port 24 of localhost
Server is listening on port 25 of localhost
Server is not listening on port 26 of localhost
Server is not listening on port 27 of localhost
Server is not listening on port 28 of localhost
Server is not listening on port 29 of localhost
Server is not listening on port 30 of localhost
Server is not listening on port 31 of localhost
Server is not listening on port 32 of localhost
Server is not listening on port 33 of localhost
Server is not listening on port 34 of localhost
Server is not listening on port 35 of localhost
Server is not listening on port 36 of localhost
Server is not listening on port 37 of localhost
Server is not listening on port 38 of localhost
Server is not listening on port 39 of localhost
Server is not listening on port 40 of localhost
Server is not listening on port 41 of localhost
Server is not listening on port 42 of localhost
Server is not listening on port 43 of localhost
Server is not listening on port 44 of localhost
Server is not listening on port 45 of localhost
Server is not listening on port 46 of localhost
Server is not listening on port 47 of localhost
Server is not listening on port 48 of localhost
Server is not listening on port 49 of localhost
Server is not listening on port 50 of localhost
Server is not listening on port 51 of localhost
Server is not listening on port 52 of localhost
Server is not listening on port 53 of localhost
Server is not listening on port 54 of localhost
Server is not listening on port 55 of localhost
Server is not listening on port 56 of localhost
Server is not listening on port 57 of localhost
Server is not listening on port 58 of localhost
Server is not listening on port 59 of localhost
Server is not listening on port 60 of localhost
Server is not listening on port 61 of localhost
Server is not listening on port 62 of localhost
Server is not listening on port 63 of localhost
Server is not listening on port 64 of localhost
Server is not listening on port 65 of localhost
Server is not listening on port 66 of localhost
Server is not listening on port 67 of localhost
Server is not listening on port 68 of localhost
Server is not listening on port 69 of localhost
Server is not listening on port 70 of localhost
Server is not listening on port 71 of localhost
Server is not listening on port 72 of localhost
Server is not listening on port 73 of localhost
Server is not listening on port 74 of localhost
Server is not listening on port 75 of localhost
Server is not listening on port 76 of localhost
Server is not listening on port 77 of localhost
Server is not listening on port 78 of localhost
Server is not listening on port 79 of localhost
Server is listening on port 80 of localhost
0 comments:
Post a Comment