Page 1 of 2 12 LastLast
Results 1 to 20 of 35
  1. #1
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default Game Host Scanner

    Hey,
    um building a software that will scan all the pcs connected to the network and search whether anyone has hosted any games (counter strike, warcraft, fifa). lets assume i know the ports the games use.

    first of all i need to search all the connected pcs in some specific sockets...
    suppose i want to scan 172.16.16.1 to 172.16.25.255 addresses and search in ports 123,234,345...what should i do or what should i study?

    i just need to know how to scan a range of ip addresses using java?

    heres a screenshot of GUI:
    Last edited by GhosT; 09-30-2008 at 07:17 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    The Socket class can be used to connect to IP addresses.

  3. #3
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    can u please provide an example? socket needs 2 parameters from client to server communication, hostname and port...but is it possible to make it serverless...just connect to all the pc on port 123 (ie) if active and get some data?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    connect to all the pc on port 123
    No, I don't know how or if that can be done.
    Your search routine would use a nested loop.
    Outer loop over the IP addresses you gave
    Inner loop over the ports you gave.
    The Socket class is what you would use to try to connect to each port at each IP address.

    Each address you try to connect to would have to have software ready to talk to you. Firewalls will prevent this, unless the PCs are configured to let you connect.

  5. #5
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    read the next post...this is solved :D
    Last edited by GhosT; 09-28-2008 at 09:04 PM.

  6. #6
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    i think um almost close...these are the codes
    Server:
    Java Code:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    
    class Server {
       public static void main(String args[]) {
          String data = "1.Warcraft.DotA.GhosT.1";
          try {
             ServerSocket srvr = new ServerSocket(1234);
             Socket skt = srvr.accept();
             System.out.print("Client has connected!\n");
             PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
             System.out.print("Sending string: " + data + "\n");
             out.print(data);
             out.close();
             skt.close();
             srvr.close();
          }
          catch(Exception e) {
             System.out.print("Whoops! It didn't work!\n");
          }
       }
    }
    Client Side Scanner:
    Java Code:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    
    public class LocalScan {
      public static void main(String[] args) {
       String ip = "192.168.11.217";
    	for (int i=1230;i<=1240;i++){
       testPort(ip,i);
    }
        System.out.println("Completed");
      }
    
      private static void testPort(String ip, int i) {
             String data = "";
        try {
          Socket sock = new Socket(ip, i);
    		   System.out.println("Game Found!");
             BufferedReader in = new BufferedReader(new
             InputStreamReader(sock.getInputStream()));
    
             while (!in.ready()) {}
    	   data = in.readLine();
    
    	   StringTokenizer strTokToken = new StringTokenizer(data, ".", false);
             System.out.println("Game Information:");
             while (strTokToken.hasMoreTokens())
             {
                 System.out.println(strTokToken.nextToken());
             }
    
    	   //System.out.println(data); // Read one line and output it
             in.close();
    
        } catch (java.io.IOException e) {
          System.out.println("Port " + i + " on "+ip+" is not in use.");
        }
      }
    }
    now the problem is when the client finds the server and the data, the server quits...but i need it to run because other clients will also check the game...the server will run untill its closed by the creator. i think it will need thread...and i know nothing about it...:S any help??
    Last edited by GhosT; 09-28-2008 at 10:29 PM.

  7. #7
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    another problem...this is the function i made to read IPs from a file and show it in a JTable but its not working, even its not returning any errors..
    Java Code:
    private void initTable() {
            String[] col = {"IP Addresses"};
            int row = 20;
            String[][] rows = new String [row][1];
            int i = 0;
            
            /*for (i = 0; i < row; i++) {
                rows[i][0] = "172.16.24.75";
            }*/
            
        try{
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new FileInputStream("iplist.txt");
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        //Read File Line By Line
        while (in.available()!= 0)   {
          // Print the content on the console
          rows[i][1]= br.readLine();
          i++;
        }
        //Close the input stream
        in.close();
        }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }
    
    
            MyTableModel tm = new MyTableModel();
            tm.setColumnNames(col);
            tm.setData(rows);
            table.setModel(tm);
    
    }
    when i run this it returns:


    init:
    deps-jar:
    compile-single:
    run-single:
    Error: 1
    BUILD SUCCESSFUL (total time: 4 seconds)



    can any one help?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    the client finds the server and the data, the server quits
    That's because the code in the server only does a single accept. After that it exits. If you want more than one accept, you'll need to have a loop.

  9. #9
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    in that case looping wont do i think...i have to use thread...and what about the initTable() function? u know whats wrong?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    You will both a loop and threads in the server. The loop to do the accept. the thread to handle the communications on socket returned by accept.
    Sorry I haven't worked with Tables.
    when i run this it returns
    What does run mean? Compile or execute. I don't recognize the format of the error messages you show.

  11. #11
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    thats from netbeans and u dont use IDE...i got ur point...i implemented the loop...

    theres another problem...when the client starts scanning for ports in different ips the GUI hangs... even the label.setText() or any other simple mothods dont work untill the scan is completed...the last output is shown in label.setText()...so i think i'll need thread here too...each thread to scan different ip...am i right??

    um 22 yrs old and still learning so please dont get annoyed if i ask something noobish...:D
    Last edited by GhosT; 09-29-2008 at 11:00 PM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    You need to use a thread different from the GUI's thread anytime the code is going to take a long time or block. Start your thread to do the scan and exit your listener or whatever as soon as possible to give the thread back to the GUI. Remember to have your new thread test a flag such as a boolean to know if the user wants the thread to end. You'd set this flag via some GUI listener such as a button or menuitem.

  13. #13
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    yea, i have a stop button and one flag. Should i start a thread for the whole scan...thn i will get all the results after the scan but i need it like real time...so i think i need separate thread for every ip scan...correct me if um wrong.

    can u please mention where should i add thread codes in the client side scanner LocalScan class?? i dunt have sufficient knowledge about thread...:P

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    so i think i need separate thread for every ip scan...correct me if um wrong.
    Maybe & maybe not. I don't know if you want to do this in parallel or serially.

    I'm not sure which is client and which is server for you. Can you define them for you app?
    software that will scan
    Does the server do this scanning? And the clients are the passive ones waiting for this server to find them.
    Normally the server is the passive one waiting for the client to connect to it.

  15. #15
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    I don't know if you want to do this in parallel or serially
    if its serial then all the results will be shown after the scan is complete...and if its parallel thn i can display whenever one server is found.
    I'm not sure which is client and which is server for you. Can you define them for you app?
    when someone host a game then its a server that places some information in 1234 port. when the same software is run for searching games thn it will act as a client and check for 1234 port in every IP that is in the iplist.txt file...and whenever it finds 1234 port open in any IP it will collect the information and display in the table.

    if someone creates a game on a machine and then start scanning it will find its own game if its own IP is in the iplist.txt file

    theres a demo...please take a look...its an exe and will run without java installed.
    mediafire.com/?sharekey=22e2cb24bb83494bd2db6fb9a8902bda
    Last edited by GhosT; 09-30-2008 at 03:55 PM.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Ok a server hosts a game and waits for a client to connect to it.
    The client searches for a server to connect to.
    Sorry I don't connect to sites that use .exes

  17. #17
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    its the exe i made...and uploaded to media fire...theres no harm..please take a look...that way u'll understand the problem and help me better.

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Sorry, let's stick with java.

  19. #19
    GhosT's Avatar
    GhosT is offline Member
    Join Date
    Sep 2008
    Location
    Dhaka, Bangladesh
    Posts
    37
    Rep Power
    0

    Default

    Ok a server hosts a game and waits for a client to connect to it.
    The client searches for a server to connect to.
    yeah thats right...but the server doesnt host a game...it just send the information of hosting a game like 'hey...i have hosted a game...join me if u want'.
    Sorry I don't connect to sites that use .exes
    Sorry, let's stick with java.
    its java...i think u dont get it...common...its the converted version (JAR2EXE Converter) of the jar file of my game scanner project...okay um zipping and uploading the jar if u have allergy to exe... but take a look. please....download the zip file and unzip it and run the jar.
    Its the jar of the game scanner project
    GameScanner
    Last edited by GhosT; 09-30-2008 at 07:25 PM.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    Sorry, I've forgotten what the problem is now.

    You have a server that waits for clients to connect to it and then the server does what?

    What does the client do when it gets a connection?

    Who plays the game?

    Port numbers up to 4096 can be used by other apps. It'd be better to use higher numbered ports for your games.

    I tried connecting to the site you posted a link for. It put up a page saying it was loading something. I bailed out before waiting for it to finish what ever it was trying to load. I'm on a dial up line that is slow. Your page obviously has more on it than I am interested in getting. I was expecting a simple page with a link, not some app that will run on my browser.
    Last edited by Norm; 09-30-2008 at 09:53 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Looking Up the Address of a Host
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:11 PM
  3. Getting the host of the applet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:56 PM
  4. Replies: 0
    Last Post: 02-15-2008, 08:41 AM
  5. Getting host name/address
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-19-2007, 04:34 PM

Posting Permissions

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