[VB.NET/C#] Check Minecraft Server Status [Snippet]

Very simple snippet I whipped up, figured I would share with you all.

Imports:
C#

using System.Net.Sockets;

VB.NET

Imports System.Net.Sockets

Functions:
C#

public object CheckStatus()
{
	TcpClient MinecraftServer = new TcpClient();
	try {
		MinecraftServer.Connect("IP/DNS to server Here", 25565);
		return true;
	} catch (Exception Excep) {
		return false;
	}
}

VB.NET:

Public Function CheckStatus()
        Dim MinecraftServer As New TcpClient
        Try
            MinecraftServer.Connect("IP/DNS to server Here", 25565)
            Return True
        Catch Excep As Exception
            Return False
        End Try
    End Function

Haha! Idea. :smiley: I’m gonna make a little tool.

EDIT: I’m done with it, I’ll put it up tomorrow. Couldn’t figure out how to get it to let you put your own port in, too, but I did get it so you can put in your own ip. I’ll have to look into that.

Just edit the port where the 25565 is, put yours in there. pretty simple :stuck_out_tongue: .

I tried that, and I mean user input via a textbox for the port as well as the ip. It only lets me do an input for the ip or the port. Not both. When I do both it comes up with an error. And I’m gonna post it right now :smiley:

Try parsing the textbox’s text into an int:

    MinecraftServer.Connect("IP/DNS to server Here", int.Parse(YourTextBox.Text));

That’s cause the IP and port are seperate, you’d want something like this:


bool CheckServer(string server)
{
	try
	{
		new TcpClient().Connect(server.Split(':')[0], int.Parse(server.Split(':')[1]));
		return true;
	}
	catch{ return false; }
}

Then use like:


MessageBox.Show("Server" + CheckServer("google.com:25565") ? "Online!" : "Offline");

Thanks! That worked! I’ll reupload in a bit.

Bam. Check it out, I’m going to try to add some more things!