[an error occurred while processing this directive]

Low port Scanner


In this section, you will learn how to get local port number of the local machine. Here, we define the name of program LowPortScanner. In this we check the argument and create a socket object. This program mainly display the massage on the command line very low port information. The java.net package provides two classes a socket and ServerSocket that implement the client side of the connection and server side of the connection, respectively. The Socket classes are used to represent the connection between a client program and a server program. 


Here is the code of this program:

import java.net.*;
import java.io.*;

public class LowPortScanner {
  public static void main(String[] args) {
    String host = "localhost";
    if (args.length > 0) {
      host = args[0];
    for (int i = 1; i < 1024; i++) {
      try {
        Socket s = new Socket(host, i);
        System.out.println("There is a server on port " + i + " of " + host);
      catch(UnknownHostException ex){
      catch (IOException ex) {}


Output of this program:

C:\rose>java LowPortScanner
There is a server on port 135 of localhost


Download of this program.



[an error occurred while processing this directive]