1
0
mirror of https://e.coding.net/circlecloud/CTZLauncher.git synced 2024-11-24 02:28:49 +00:00
CTZLauncher/MinecraftServerInfo/Program.cs

50 lines
2.2 KiB
C#
Raw Normal View History

2015-08-12 11:49:29 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace MinecraftServerInfo
{
class Program
{
static void Main(string[] args)
{
2015-08-13 10:30:27 +00:00
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
2015-08-12 11:49:29 +00:00
try
{
//01 00
//0F 00-2F 09 31 32 37 2E 30 2E 30 2E 31 63 DD 01
//client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
//client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);
2015-08-13 10:30:27 +00:00
client.Connect("CityCraft.cn", 25565);
//client.Connect("four.mengcraft.com", 11133);
2015-08-12 11:49:29 +00:00
Console.WriteLine("开始连接");
if (client.Connected)
{
Console.WriteLine("发送数据");
2015-08-13 10:30:27 +00:00
client.Send(new byte[] { 0x0F, 0x00, 0x04, 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x63, 0xDD, 0x01 });
2015-08-12 11:49:29 +00:00
client.Send(new byte[] { 0x01, 0x00 });
Console.WriteLine("读取头数据");
byte[] header = new byte[5];
client.Receive(header, header.Length, SocketFlags.None);
Console.WriteLine(BitConverter.ToString(header));
byte[] buffer = new byte[1024];
int recover = client.Receive(buffer, buffer.Length, SocketFlags.None);
byte[] data = new byte[recover];
Console.WriteLine("数据流长度: " + recover);
Array.Copy(buffer, data, recover);
Console.WriteLine(BitConverter.ToString(data));
Console.WriteLine(Encoding.UTF8.GetString(data));
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}