Click here to Skip to main content
13,294,516 members (57,635 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 22 Aug 2004

Game Server Scanner

, 22 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Port scanner to find game servers on a LAN.


Sample Image - gfxscan.jpg


gfxscan is a simple port scanner developed to search for remote computers on LAN running game servers.

It sends simple UDP request asynchronously to all the IPSs on a particular port in a subnet. The port being 27015 in case of counter strike. The response is then parsed to get the details of the server. There are many additional requests which can be made to know more about the game, which I will be posting later.

I tried to find a simple port scanner for LAN and Googled a lot, but didn't find any. So I decided to write my own game server scanner.

Problems Faced

Major problem was to reduce the time wait for a read call. I got rid of it by setting option System::Net::Sockets::SocketOptionName::ReceiveTimeout as 1000.


The blocking nature of a socket can be nulled using sock->set_Blocking(false).

Major Code Fragments

  1. Creating a UDP socket, starting a new thread to read for the response from hosts if found a server, and sending UDP requests to hosts in a subnet:
    void scanServers(String* ip[],int prt,int count)
      boolRead =1;
      port = prt;
      sock = new Socket(AddressFamily::InterNetwork, 
      readThread = new Thread(new ThreadStart(this,read));
      Byte msg[]= System::Text::Encoding::ASCII->GetBytes("xxxxinfo\0");
      Byte msg2[]= new Byte[1000];
      msg[0] = 0xff;
      msg[1] = 0xff;
      msg[2] = 0xff;
      msg[3] = 0xff;
      for(int i=0;i<count;i++)
        IPAddress* ipAdd = IPAddress::Parse(ip->GetValue(i)->ToString());
        IPEndPoint* endPoint = new IPEndPoint(ipAdd,port);
        EndPoint* senderRemote = __try_cast<EndPoint*>(endPoint);
          sock->SendTo(msg, 0, msg->Length, SocketFlags::None, endPoint);
        catch ( SocketException* se )
          //MessageBox::Show(se->Message,"exception while sending",
               MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  2. Setting the non-blocking and time wait options, reading from hosts on the same socket, decoding the message, and then sending it to display the message correctly:
    void read()
      IPEndPoint* sender = new IPEndPoint(IPAddress::Any, port);
      EndPoint* senderRemote = __try_cast<EndPoint*>(sender);
      Byte msg2[]= new Byte[1000];
          int iR = sock->ReceiveFrom(msg2, 0, msg2->Length, 
                        SocketFlags::None, &senderRemote);
          Char chars[] = new Char[2000];
          Decoder* d = Encoding::UTF8->GetDecoder();
          int charLen = d->GetChars(msg2, 0, msg2->Length, chars, 0);
          String* str = new String(chars); 
        catch (SocketException* se)
          MessageBox::Show(se->Message,"exception while sending", 
                  MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
      this->labelStatus->set_Text(new String("Scan Complete."));

I am looking forward to making a class to provide a neat interface to find game servers on LAN, and to ping them for more information of the game, like no. of players, map being played, and status of each player.

Happy Gaming till then :)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
gfx_sikander aka sam aka Wicked_SuNny. call him by any of these names. Gfx is pusuing B.Tech in computer science and engineering at International institute of information technology hyderabad. Currently, he in 4th year and looking forward to explore .Net Technology and its competitors. He is programming since the age of 14. His area of interest are C++, ASP.Net, Game programming and Compter Networks. He likes to make web pages and flash animations. It must also be mentioned here that gfx does not usually speak about himself in the 3rd person. Smile | :)

visit his space to know more about him ...

You may also be interested in...


Comments and Discussions

GeneralRe: Game server scanner. Pin
KingOleg12-Sep-06 1:34
memberKingOleg12-Sep-06 1:34 
GeneralGame server scanner. Pin
Andrewfx9-Oct-05 0:36
memberAndrewfx9-Oct-05 0:36 
i got a problem while runnig your app. it says Error while initializing application (0xx0000135). Press OK to exit.
Just wonder: i have a russian WinXp and you have provided only EN(US) dlls. Would it be worth to change the language and settings to english?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 23 Aug 2004
Article Copyright 2004 by gfx_sikander
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid