Ping Server with port

neoryudo

Newcomer
Joined
Apr 11, 2012
Messages
2
ok so i am really sorry if this has been answered before i am not the best at at VB.net by far anyways i have a problem, i have written some code in a VB i have made that pings a server and give me and MS and writes it on the app, now what i need is it to be able to ping the port in the same equation but i am not sure how and if i can even implement it into my code, the reason behind this is that it pings a game server, so when the servers are not up they close a port,

anyways i will put some code here and see if you guys think i can implement it if not any pointers will be greatly appreciated

Code:
 If InternetConnection() = True Then
                Dim p As System.Net.NetworkInformation.Ping = New System.Net.NetworkInformation.Ping
                Dim prep As System.Net.NetworkInformation.PingReply
                'if server = 0 then ping server and 
                If (server = 0) Then
                    Dim url As String = "79.110.94.195"
                    prep = p.Send(url)
                    If (prep.Status = System.Net.NetworkInformation.IPStatus.Success) Then
                        Dim address As String = prep.Address.ToString
                        Dim time As String = prep.RoundtripTime.ToString
                        Label3.Text = (time + " Ms")
                        server_pic.Image = Image.FromFile("config\server_up.png")
                    Else
                        Dim status As String = prep.Status.ToString
                        server_pic.Image = Image.FromFile("config\server_down.png")
                        Label3.Text = ("0 Ms")
                    End If
 
A ping request simply checks if there is something active on the specified IP address, there really isn't the concept of pinging a port.

If the ping request succeeds you could try opening a connection on the specified port and see if anything accepts.
 
Yeah I didn't mean to "ping the port " bit through a port number, website allow you to connect to them through port 80 and online games allow you to connect to the servers through for example port 4500, now if the servers are down for some reason they will close off port 4500 to stop people connecting to the server, but my code doesn't ping through any port so even of the game servers are offline for users, my code is still saying they are online because it is not trying to ping through the closed port? Do you understand where I am coming from?
 
Last edited:
You could probably try using a TcpClient to open a connection to the correct port and see if it connects, if it fails to open then the server is probably offline.
 
Back
Top