Program to know the Sockets of a System using Java

Program to know the Sockets of a System using Java

     This is the program to find out the inused ports in the system. The range between 0-1024 ports are reserved for internal system usage. In that some of the ports are unused. Socket object is used to find out the required ports. Socket is created with the combination of IP address and port number.

import java.io.*;
import java.net.*;
class Sock
{
public static void main(String args[])
{
                        for(int port=0;port<1024;port++)

                        {
                                    try
                                    {
                                    Socket s=new Socket("165.165.1.35",port);
                                    System.out.println("The Ports are:"+s);
                                    }
                                    catch(Exception e)
                                    {}
                        }
           
           
}
}

Output

E:\java Sock
The Ports are:Socket[addr=AK1-35.kcetdc/165.165.1.35,port=135,localport=2054]
The Ports are:Socket[addr=AK1-35.kcetdc/165.165.1.35,port=139,localport=2058]
The Ports are:Socket[addr=AK1-35.kcetdc/165.165.1.35,port=445,localport=2366]
The Ports are:Socket[addr=AK1-35.kcetdc/165.165.1.35,port=523,localport=2444]

No comments:

Post a Comment

Creating Objects

Creating Objects                  Creating objects means to allocate memory space for all the instance variables of the objects. S...