VB.NET服务器在线状态查询 [英] VB.NET server online status query

查看:157
本文介绍了VB.NET服务器在线状态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello everone



我在查找代码时遇到一些问题

我的情况是我们有局域网并且有几个服务器启动和运行,例如。使命召唤4

现在我想创建一个简单的程序,检查我的服务器是否在端口28960上运行,如果它在线然后图片框变成绿色而不是红色而且我将有一个文本框设置检查间隔



那么如何查询端口是否在线检查?



关注

Hello everone

I am having some problems with finding a code
My situation is we have lan partys and have a couple of servers up and running eg. Call of duty 4
Now i want to create a simple program that checks if my server is running on port 28960 if its online then the picturebox turns green and not then red and also i will have a textbox to set the interval to check

So how do i query a port to check if its online or not?

Regards

推荐答案

你没有。您向服务器发送查询,服务器必须响应。如果服务器没有任何方法,您可以调用以获取表示它正在运行的响应,您必须查阅正在运行的服务器上的文档,以查看是否有任何其他方法可用于ping服务器。
You don't. You send a query to the server and the server has to respond. If the server does not have any method you can call to get a response that denotes that it is running, you have to consult the documentation on the server you're running to see if there is any other method you can use to "ping" the server.


您无法ping端口,因为ping操作不在端口级别运行。但是,您可以通过使用TCP或UDP连接到端口来检查本地计算机上是否正在使用它,或者它是否在远程计算机上打开。



查看远程端口是否已打开:

You can't ping a port because the ping operation does not operate at port level. You can however check to see if it is in use on the local computer or if it is open on the remote computer by means of connecting to the port using either TCP or UDP.

See if remote port is open:
Function CheckPortOpen(ByVal hostname As String, ByVal portnum As Integer) As Boolean

    Dim ipAddr As IPAddress = CType(Dns.GetHostAddresses(hostname)(0), IPAddress)

    Try
        Dim sock As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Console.WriteLine("Testing " & hostname & ":" & portnum)
        'Open connection to host
        sock.Connect(ipAddr, portnum)
        If (sock.Connected = True) Then
            sock.Close()
            sock = Nothing
            Return True
       End If

    Catch sex As SocketException
        If sex.ErrorCode = 10061 Then
            Return False
        Else
            Return Nothing
        End If
    End Try
End Function


这篇关于VB.NET服务器在线状态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆