Results 1 to 5 of 5
Like Tree2Likes
  • 2 Post By doWhile

Thread: Java Port Scanner

  1. #1
    sixxvirus's Avatar
    sixxvirus is offline Member
    Join Date
    Oct 2011
    Location
    Solana Beach, CA
    Posts
    23
    Blog Entries
    3
    Rep Power
    0

    Default Java Port Scanner

    I have been working my way web pages and blogs learning the in's and out's of Network applications through
    Java, today I made a simple port scanner to see if there is any activity on any ports on my computer.
    The program uses a loop to scan through ports 1 to 65535, the source code in below, feel free to leave
    any comment or suggestion about this code or anything else.

    *Happy Coding*


    /* AllPortScanner.java
    * Find out which of the 0 <= ports< 65536 seem
    * to be hosting TCP servers.
    */
    import java.net.*;
    import java.io.*;
    public class AllPortScanner{
    public static void main(String[] args){
    String host="localhost";
    if(args.length>0){
    host=args[0];
    } // end condition
    try{
    InetAddress address=InetAddress.getByName(host);
    for(int index=0; index<65536; index++){
    try{
    Socket s=new Socket(address, index);
    System.out.println("Server on port "+index+" of "+host);
    if(index==1024){ // low ports
    System.out.println("End of low end ports");
    }else if(index==65535){ // high ports
    System.out.println("End of high end ports");
    } // end condition
    }catch(IOException e){
    // no server on this port
    } // end exception
    } // end loop
    }catch(UnknownHostException e){
    System.err.println(e);
    } // end exception
    } // end main
    } // end class

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Java Port Scanner

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Java Port Scanner

    Moved from Networking. The technical forums are for questions, not for publicizing your work.

    I guess that's why the StackOverflow moderators removed your cross post there.

    db
    Last edited by DarrylBurke; 05-16-2012 at 07:23 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Java Port Scanner

    ...and a user whose name contains the word virus, posting code that is a port scanner - makes me cautious of the source
    DarrylBurke and Fubarable like this.

  5. #5
    sixxvirus's Avatar
    sixxvirus is offline Member
    Join Date
    Oct 2011
    Location
    Solana Beach, CA
    Posts
    23
    Blog Entries
    3
    Rep Power
    0

    Default Re: Java Port Scanner

    I am learning networking programming, and the "Java Network Programming" by O'REILLY, the whole book is about port scanners. I dont know how to make any other program.

Similar Threads

  1. Port Forwarding In Java?
    By anthropamorphic in forum Networking
    Replies: 10
    Last Post: 08-11-2011, 11:01 PM
  2. Java Serial Port
    By Khan05 in forum New To Java
    Replies: 2
    Last Post: 07-21-2011, 10:56 PM
  3. Java Serial Port
    By Khan05 in forum Java Applets
    Replies: 1
    Last Post: 07-21-2011, 10:09 PM
  4. port scanner
    By Engineer in forum New To Java
    Replies: 1
    Last Post: 09-04-2010, 04:49 PM
  5. COM Port Detection in Java
    By talasilasumanth in forum Forum Guides
    Replies: 1
    Last Post: 09-10-2008, 04:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •