Download Horizon :: Staff Members :: Save Vault :: XboxMB YouTube


Old 02-25-2011   #1 (permalink)

Kink's Avatar
Humph.
Join Date: Sep 2010
Posts: 2,742
Thanks: 3,507
Default [VB.NET/C#] Check Minecraft Server Status [Snippet]

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

Imports:
C#
PHP Code:
using System.Net.Sockets
VB.NET
PHP Code:
Imports System.Net.Sockets 

Functions:
C#
PHP Code:
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:
PHP Code:
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 
__________________

Last edited by Kink; 02-25-2011 at 04:02 PM.
Kink is offline
Reply With Quote
The following users thanked this post: Jordannnnn, Psyco, Speak


Old 02-25-2011   #2 (permalink)
Regular Member
Jeremy Q's Avatar
Join Date: Sep 2010
Posts: 1,977
Thanks: 1,301
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Haha! Idea. 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.
__________________

Last edited by Jeremy Q; 02-26-2011 at 01:00 AM.
Jeremy Q is offline Send a message via AIM to Jeremy Q
Reply With Quote


Old 02-26-2011   #3 (permalink)

Kink's Avatar
Humph.
Join Date: Sep 2010
Posts: 2,742
Thanks: 3,507
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Quote:
Originally Posted by lee74saurus r3x View Post
Haha! Idea. 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 .
__________________
Kink is offline
Reply With Quote




Old 02-26-2011   #4 (permalink)
Regular Member
Jeremy Q's Avatar
Join Date: Sep 2010
Posts: 1,977
Thanks: 1,301
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

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
__________________
Jeremy Q is offline Send a message via AIM to Jeremy Q
Reply With Quote


Old 02-26-2011   #5 (permalink)
Hetelek's Avatar
sh042067
Join Date: Sep 2010
Location: NY
Posts: 1,676
Thanks: 1,014
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Try parsing the textbox's text into an int:
Code:
    MinecraftServer.Connect("IP/DNS to server Here", int.Parse(YourTextBox.Text));
__________________





Hetelek is offline Send a message via AIM to Hetelek
Reply With Quote


Old 02-26-2011   #6 (permalink)

Oscar's Avatar
Join Date: Oct 2010
Location: UK
Posts: 1,071
Thanks: 1,464
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Quote:
Originally Posted by lee74saurus r3x View Post
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
That's cause the IP and port are seperate, you'd want something like this:

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

Then use like:
PHP Code:
MessageBox.Show("Server" CheckServer("google.com:25565") ? "Online!" "Offline"); 
Oscar is offline Send a message via AIM to Oscar
Reply With Quote


Old 02-26-2011   #7 (permalink)
Regular Member
Jeremy Q's Avatar
Join Date: Sep 2010
Posts: 1,977
Thanks: 1,301
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Quote:
Originally Posted by sh042067 View Post
Try parsing the textbox's text into an int:
Code:
    MinecraftServer.Connect("IP/DNS to server Here", int.Parse(YourTextBox.Text));
Thanks! That worked! I'll reupload in a bit.
__________________
Jeremy Q is offline Send a message via AIM to Jeremy Q
Reply With Quote


Old 02-26-2011   #8 (permalink)
Regular Member
Jeremy Q's Avatar
Join Date: Sep 2010
Posts: 1,977
Thanks: 1,301
Default Re: [VB.NET/C#] Check Minecraft Server Status [Snippet]

Bam. Check it out, I'm going to try to add some more things!
__________________
Jeremy Q is offline Send a message via AIM to Jeremy Q
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:06 PM.


 

Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
COPYRIGHT (c) 2010 - 2013 - XboxMB - DESIGN BY:
EDENWEBS.COM