Home Java Network Low port Scanner

Related Tutorials


 
 

Share on Google+Share on Google+

Low port Scanner

Advertisement
In this section, you will learn how to get local port number of the local machine.

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){
  System.err.println(ex);
  break;
  }
  catch (IOException ex) {}
  }
  }

 

Output of this program:

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

 

Download of this program.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Related Tutorials

Discuss: Low port Scanner  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com