Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: How to find the ipaddress of hackers who enter through open ports to PC?

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How to find the ipaddress of hackers who enter through open ports to PC?

    hi all,
    how to find the ipaddress of hackers who enter through open ports to pc. is it possible with the help
    of java.net package.please help me. i am new to java.if possible how can i move forward?


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: finding ipaddress

    Hello tej,

    You would need to write some kind of port watching program that looks for unauthorised incoming connections.

    Are you looking into this as a personal project or are you under attack from hackers?

    A good firewall will protect you.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    Quote Originally Posted by JavaPF View Post
    Hello tej,

    You would need to write some kind of port watching program that looks for unauthorised incoming connections.

    Are you looking into this as a personal project or are you under attack from hackers?

    A good firewall will protect you.

    thank youy very much for the replay.i written a program that looks over the opened ports .but the proble is i am not able to get the incoming ipaddress from the port.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: finding ipaddress

    Could you please post your code? I will take a look and see if I can add the method to get the ip address.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    here is mycode

    import java.net.*;
     
     public class PortScannerApp
     
    {
     
            public static void main(String args[])
           {
              Socket ServerSok ;
               int  startPortRange=0;
               int  stopPortRange=65536;
     
                  for(int i=startPortRange; i <=stopPortRange; i++)
          {
                            try
                            {
                          ServerSok = new Socket("127.0.0.1",i);
                         //  System.out.println(""+ServerSok.getRemoteSocketAddress());
                           //System.out.println(""+ServerSok.getLocalSocketAddress());
                    System.out.println("Port in use: " + i );{
     
                     ServerSok.close();
                           }
                    catch (Exception e)
                           {
                    e.printStackTrace();
                           }
            System.out.println("Port not in use: " + i );
     
            }
           }
            }
     }
    Last edited by JavaPF; May 1st, 2009 at 07:13 AM. Reason: Please add code tags...

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: finding ipaddress

    Hey tej,

    There were all sorts of errors in that code. I've cleaned it up for you though..

    public class PortScannerApp {
     
        public static void main(String args[]){
     
              Socket ServerSok ;
              int  startPortRange=0;
              int  stopPortRange=65536;
     
              for(int i=startPortRange; i <=stopPortRange; i++) {
     
                  try
                  {
                  ServerSok = new Socket("127.0.0.1",i);
                  //  System.out.println(""+ServerSok.getRemoteSocketAddress());
                  //System.out.println(""+ServerSok.getLocalSocketAddress());
                  System.out.println("Port in use: " + i );
     
                  ServerSok.close();
                  }catch (Exception e){
                   e.printStackTrace();
                  }
     
                  System.out.println("Port not in use: " + i );
                 }
          }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    the above code is scanning the ports.and displaying which port is used and which port is in unused.
    its displaying the output port in use &not in use at the same number.
    [port in use:80
    port not in use:80]
    but it takes very huge time to scan the total ports(0 to 56635).from these opened ports how i can get
    the hackers details(i.e ipaddress,location).please help me..
    Last edited by tej; May 5th, 2009 at 04:04 AM.

  8. #8
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: finding ipaddress

    Hello tej,

    Take a look at this code.

    It will watch a port for incoming connections. When someone connects, their IP is printed and the connection is closed.

    In this case we are watching port 101.

    import java.net.*;
    import java.io.*;
     
    public class PortMonitor {
     
        /**
         * JavaProgrammingForums.com
         */
        public static void main(String[] args) throws Exception {
     
            // Port to monitor
            final int myPort = 101;
            ServerSocket ssock = new ServerSocket(myPort);
            System.out.println("port " + myPort + " opened");
     
            Socket sock = ssock.accept();
            System.out.println("Someone has made socket connection");
     
            OneConnection client = new OneConnection(sock);
     
        }
     
    }
     
    class OneConnection {
        Socket sock;
        BufferedReader in = null;
        DataOutputStream out = null;
     
        OneConnection(Socket sock) throws Exception {
            this.sock = sock;
            in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            out = new DataOutputStream(sock.getOutputStream());
     
            // Get IP and send message
            System.out.println(sock.getRemoteSocketAddress());
            out.writeBytes("Go away!");
     
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  9. #9
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    thank u very much.when i executed the code by changing the port to 5222 it giving the exception but i am not getting
    the ipaddress .i tested this code in lan to find my friends ipaddress.

    Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java :359)
    at java.net.ServerSocket.bind(ServerSocket.java:319)
    at java.net.ServerSocket.<init>(ServerSocket.java:185 )
    at java.net.ServerSocket.<init>(ServerSocket.java:97)
    at remopteipaddress.PortMonitor.main(PortMonitor.java :20)

  10. #10
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Smile Re: finding ipaddress

    Quote Originally Posted by tej View Post
    thank u very much.when i executed the code by changing the port to 5222 it giving the exception but i am not getting
    the ipaddress .i tested this code in lan to find my friends ipaddress.

    Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java :359)
    at java.net.ServerSocket.bind(ServerSocket.java:319)
    at java.net.ServerSocket.<init>(ServerSocket.java:185 )
    at java.net.ServerSocket.<init>(ServerSocket.java:97)
    at remopteipaddress.PortMonitor.main(PortMonitor.java :20)
    I think you are getting this Exception because port 5222 is already in use. This program monitors the port by opening it first. Try running the program and opening a port that is not in use. Do you get the same error?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  11. #11
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    Quote Originally Posted by JavaPF View Post
    I think you are getting this Exception because port 5222 is already in use. This program monitors the port by opening it first. Try running the program and opening a port that is not in use. Do you get the same error?
    ok. i changed the port its working fine .but if i want to scan total ports(using loop) its taking too much time.
    is there any alternative to scan ports fastly and display the hacker ipaddress.
    and one more doubt...
    is it usefull to use netstat command to display active connections and parsing the result using java code?
    the netstat command display active connections(foriegn address) is the foreign address is enough to trace hacker.

  12. #12
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: finding ipaddress

    The problem with your last code is that the hacker would have to be attempting to connect to the exact port at the exact time it is scanned. I can't see this method ever working correctly. I think the fastest way would be to gather a list of all ports in use and then watch those ports rather than constantly scanning the giant port range.

    You could always use the code I posted earlier as a 'hunny trap' You can open a port that is not normally used, and when a hacker does a port scan or attempts to connect to the open port, their IP will be displayed. This is a much more effective method of catching an intruder.

    Yes the Netstat command is a good way to show connected IPs although I am unsure as to how to parse this in Java. It'll be easier to do it manually and write the result down!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  13. #13
    Junior Member
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: finding ipaddress

    ok.this discussion gives me lot of usefull information .ok now i move forther with this information
    thank u very much

  14. #14
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Smile Re: finding ipaddress

    Quote Originally Posted by tej View Post
    ok.this discussion gives me lot of usefull information .ok now i move forther with this information
    thank u very much
    No problem tej, I hope this helps you to complete your task.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. How to find location of ipaddress using Java
    By tej in forum Java Networking
    Replies: 8
    Last Post: September 8th, 2012, 06:05 AM