im trying to examine the data from a script that i believe is written in C#, i need to find out exactly how its communicating with the server and am going to try to replicate it in php, i have what i thought worked, but the server wont send back any data to me.. can anyone look at this and tell me if its doing what i think:
I believe this is taking the hex data thats listed as inputtobesent and sending it to the server via udp and waiting for a response, but when i send the same data in php the server wont respond..
thanks to anyone who might be able to help
sorry for the long post, i wanted to make sure i have it all in there
I believe this is taking the hex data thats listed as inputtobesent and sending it to the server via udp and waiting for a response, but when i send the same data in php the server wont respond..
thanks to anyone who might be able to help
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.IO;
namespace FLPing
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
IPHostEntry lipa;
if(args.Length < 3)
{
Console.WriteLine("Freelancer Server Ping Utility (version 1.0)\n");
Console.WriteLine("flping [WEB OUTPUT]");
return;
}
try
{
Convert.ToInt32(args[1]);
}
catch
{
Console.WriteLine("Invalid PORT parameter - must be numeric and less than 65530.");
return;
}
try
{
Convert.ToInt32(args[2]);
}
catch
{
Console.WriteLine("Invalid TIMEOUT parameter - must be a valid integer value.");
return;
}
try
{
lipa = Dns.Resolve(args[0]);
}
catch
{
Console.WriteLine("Could not resolve server name/contact IP.");
return;
}
IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], Convert.ToInt32(args[1]));
Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);
byte[] inputToBeSent = new byte[21];
// Create the "special" packet that will return the correct data
inputToBeSent[0] = 0x00;
inputToBeSent[1] = 0x02;
inputToBeSent[2] = 0xF1;
inputToBeSent[3] = 0x26;
inputToBeSent[4] = 0x01;
inputToBeSent[5] = 0x26;
inputToBeSent[6] = 0xF0;
inputToBeSent[7] = 0x90;
inputToBeSent[8] = 0xA6;
inputToBeSent[9] = 0xF0;
inputToBeSent[10] = 0x26;
inputToBeSent[11] = 0x57;
inputToBeSent[12] = 0x4E;
inputToBeSent[13] = 0xAC;
inputToBeSent[14] = 0xA0;
inputToBeSent[15] = 0xEC;
inputToBeSent[16] = 0xF8;
inputToBeSent[17] = 0x68;
inputToBeSent[18] = 0xE4;
inputToBeSent[19] = 0x8D;
inputToBeSent[20] = 0x21;
try
{
DateTime dtStart = DateTime.Now;
// Sends datagram to the IpEndPoint specified. This call blocks.
s.SendTo(inputToBeSent, 0, inputToBeSent.Length, SocketFlags.None, lep);
// Creates an IpEndPoint to capture the identity of the sending host.
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tempRemoteEP = (EndPoint)sender;
// Creates a byte buffer to receive the message.
int iAvailable = s.Available;
int iSecCount = 0;
while(iAvailable < 1 && iSecCount < Convert.ToInt32(args[2]))
{
Thread.Sleep(100);
iAvailable = s.Available;
iSecCount++;
//Console.Write(".");
}
byte[] buffer = new byte[iAvailable];
if(iAvailable > 2)
{
DateTime dtEnd = DateTime.Now;
// Receives datagram from a remote host. This call blocks.
s.ReceiveFrom(buffer, 0, iAvailable, SocketFlags.None, ref tempRemoteEP);
int START = 92;
int END = 0;
int iServerNameLength = Convert.ToInt32(buffer[4]) - START;
END = iServerNameLength + START + 2;
//TODO: Catch error here - if data is received, but this value does not exist
byte[] bServerName = new byte[iServerNameLength];
int j=0;
for(int i=START;i 0)
{
bServerName[j] = buffer[i];
j++;
}
}
if(args.Length == 3)
{
Console.WriteLine("\nTime: " + DateTime.Now);
Console.WriteLine("Server IP: " + args[0].ToString());
Console.WriteLine("Server Port: " + args[1].ToString());
Console.WriteLine("Server Name: " + Encoding.ASCII.GetString(bServerName));
int iUserCount = Convert.ToInt32(buffer[24])-1;
int iMaxCount = Convert.ToInt32(buffer[20])-1;
Console.WriteLine("Players: " + iUserCount.ToString() + "\\" + iMaxCount.ToString()); //.ToString());
TimeSpan dtDiff = dtEnd - dtStart;
Console.WriteLine("Response Time: " + dtDiff.Milliseconds);
}
else
{
int iUserCount = Convert.ToInt32(buffer[24])-1;
int iMaxCount = Convert.ToInt32(buffer[20])-1;
TimeSpan dtDiff = dtEnd - dtStart;
StringBuilder sbWeb = new StringBuilder();
sbWeb.Append("" + DateTime.Now + "");
sbWeb.Append("" + Encoding.ASCII.GetString(bServerName) + "");
sbWeb.Append("" + args[0].ToString() + "");
sbWeb.Append("" + args[1].ToString() + "");
sbWeb.Append("" + iUserCount.ToString() + "\\" + iMaxCount.ToString() + "");
sbWeb.Append("" + dtDiff.Milliseconds + "");
Console.WriteLine(sbWeb);
}
}
else
{
if(args.Length == 3)
Console.WriteLine("\nCould not find server/port or no data received from the server.");
else
Console.WriteLine("" + DateTime.Now + "---" + args[0].ToString() + "" + args[1].ToString() + "------");
}
}
catch(Exception e)
{
Console.WriteLine("Could not communicate with server. Check options and try again.");
//Console.WriteLine(@"(www.flserver.com)");
//Console.WriteLine("Exception : " + e.ToString());
//Console.WriteLine("Stack Trace: " + e.StackTrace);
}
}
}
}sorry for the long post, i wanted to make sure i have it all in there

Help
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.



Back to top











