Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace MasterServerQuery
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- var EP = new IPEndPoint(IPAddress.Any, 0);
- var getservers = Encoding.UTF8.GetBytes(" getservers IW4 142 all");
- for (int i = 0; i < 4; i++)
- getservers[i] = 0xFF;
- UdpClient client = new UdpClient("server.alteriw.net", 20810);
- while (true)
- {
- client.Send(getservers, getservers.Length);
- var receivedata = client.Receive(ref EP);
- if (EP.Address.ToString() == "94.23.19.48")
- {
- Console.Write(Encoding.UTF8.GetString(receivedata));
- parseResponse(receivedata);
- if (Encoding.UTF8.GetString(receivedata).Contains("EOT"))
- break;
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- Console.ReadLine();
- }
- static void parseResponse(byte[] data)
- {
- var strData = Encoding.UTF7.GetString(data).Substring(4).Split('\\');
- for (int i = 0; i < strData.Length; i++)
- {
- if (strData[i].Contains("serverresponse"))
- continue;
- else if (strData[i].Contains("EOT"))
- break;
- else
- {
- var ip = new int[6];
- var port = 0;
- if (strData[i] != "")
- {
- if (strData[i].Length == 6)
- {
- for(int h = 0; h < strData[i].Length; h++)
- ip[h] = (int)strData[i][h];
- port = (256 * ip[4] + ip[5]);
- Console.WriteLine("{0}.{1}.{2}.{3}:{4}", ip[0], ip[1], ip[2], ip[3], port);
- }
- }
- if (strData[i] == "")
- strData[i + 1] = "\\" + strData[i + 1];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement