Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2008, 11:18 AM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-28-2008, 02:33 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
The Socket class can be used to connect to IP addresses.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-28-2008, 03:32 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-28-2008, 04:30 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-28-2008, 04:47 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
Default
read the next post...this is solved

Last edited by GhosT; 09-28-2008 at 09:04 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-28-2008, 09:03 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
Default
i think um almost close...these are the codes
Server:
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:
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-29-2008, 11:08 AM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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..
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?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-29-2008, 03:05 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 09-29-2008, 03:31 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
Default
in that case looping wont do i think...i have to use thread...and what about the initTable() function? u know whats wrong?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 09-29-2008, 10:33 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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.
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 09-29-2008, 10:56 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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...

Last edited by GhosT; 09-29-2008 at 11:00 PM.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 09-30-2008, 02:17 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 09-30-2008, 10:11 AM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 09-30-2008, 02:40 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
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?
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 09-30-2008, 03:51 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
Default
Quote:
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.
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 09-30-2008, 05:11 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 09-30-2008, 05:36 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 09-30-2008, 06:24 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Sorry, let's stick with java.
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 09-30-2008, 07:17 PM
GhosT's Avatar
Member
 
Join Date: Sep 2008
Location: Dhaka, Bangladesh
Posts: 37
Rep Power: 0
GhosT is on a distinguished road
Default
Quote:
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'.
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 09-30-2008, 09:49 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking Up the Address of a Host Java Tip java.net 0 04-07-2008 08:11 PM
Getting the host of the applet Java Tip Java Tips 0 03-10-2008 02:56 PM
Getting the host from where the Applet was loaded Java Tip Java Tips 0 02-15-2008 08:41 AM
Getting host name/address Java Tip Java Tips 0 11-19-2007 04:34 PM
Implementing "Game Over" in Minesweeper game based on Gridworld framework. JFlash New To Java 0 11-15-2007 11:02 PM


All times are GMT +2. The time now is 03:10 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org