使用vb.net获取RDP客户端的IP地址

时间:2013-08-08 09:19:39

标签: vb.net ip-address rdp

我正在尝试获取RDP客户端的IP地址,以便我们可以记录连接到我们服务器的所有人以及在什么时间。有没有办法用VB.net做到这一点?我尝试的所有内容都会返回服务器的IP地址。

谢谢!

1 个答案:

答案 0 :(得分:0)

摘自actual code您正在寻找的内容。

 Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim serverName As String
        Dim clientInfo As New WTS_CLIENT_INFO
        ReDim clientInfo.Address(20)
        serverName = ""
        'Server Name can be name of choice or name of server on which this application is running
        If GetSessions(serverName, clientInfo) = True Then
            Dim str As String
            str = "User Name: " & clientInfo.WTSUserName
            str &= vbNewLine & "Station Name: " & clientInfo.WTSStationName
            str &= vbNewLine & "Domain Name: " & clientInfo.WTSDomainName
            If clientInfo.WTSStationName <> "Console" Then
                str &= vbNewLine & "Client Name: " & clientInfo.WTSClientName
                str &= vbNewLine & "Client IP: " & clientInfo.Address(2) & "." & clientInfo.Address(3) & "." & clientInfo.Address(4) & "." & clientInfo.Address(5)
            End If
            MessageBox.Show(str)
        End If
    End Sub