Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get IP Address of Computer running an application through Terminal Services

Posted on 2006-11-01
15
Medium Priority
?
1,243 Views
Last Modified: 2008-01-09
Hello all,

What I want to do is get the ip address of a thin client that is running an application through terminal services on a server.  I am using vb.net...  I used        
Dim ipE As IPHostEntry = Dns.GetHostEntry(sHOstName)

but this retrieves the ip address of the terminal server, and not the client.  We have a vb6 application that successfully gets the ip of the client, and that code is posted below.  The problem I have is that I don't know how to acheive this same thing in vb.net  THIS IS URGENT!  LOTS OF POINTS!

Here is the vb6 code that accomplishes what we want to accomplish

Public Function GetWTSQueryAddress() As String
    Dim RetVal As Long, lpBuffer As Long, count As Long
    Dim p As Long, i As Integer
    Dim uName As String
   ' Dim WTSQueryInfo() As WTS_SESSION_QUERY
    Dim WTSQueryAddress As WTS_CLIENT_ADDRESS
           
    Dim SesID As Long
    'SesID = GetWTSSessionID
           
    RetVal = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
                                   WTS_CURRENT_SESSION, WTSClientAddress, lpBuffer, count)
    If RetVal Then
        p = lpBuffer
        CopyMemory WTSQueryAddress, ByVal p, LenB(WTSQueryAddress)
               
        uName = ""
        For i = 2 To 5
            uName = uName & WTSQueryAddress.address(i)
            If i < 5 Then uName = uName & "."
        Next i
     Else
        'MsgBox "An error occurred calling WTSQuerySessionInformation.  "
        uName = ""
    End If
   
    GetWTSQueryAddress = uName
End Function
0
Comment
Question by:jwebster77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17850239
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850250
Dim ipend As Net.IPEndPoint = Client.Client.RemoteEndPoint
0
 

Author Comment

by:jwebster77
ID: 17850451
I have a class now called ClientConnection.vb with the code from the example you showed me.  I suppose I want to call PublicIPAddress() from my frmlogin form where I want to use the ip address?  How do I call it?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 17850466
use notation ClassName.FUnctionName
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850471
ClientConnection.PublicIPAddress()
0
 

Author Comment

by:jwebster77
ID: 17850490
That's not working.  The only thing I get is ClientConnection.Equals and clientconnection.referencequals
0
 

Author Comment

by:jwebster77
ID: 17850498
Here is my class...

Imports System.Net.Sockets
Imports System.Reflection

Public Class ClientConnection
    Implements IDisposable
    Private Client As TcpClient
    Private PublicIP As String

    ' TODO: Add code for PublicIPAddress property here

    Public Sub New(ByVal client As TcpClient)
        ' Validate parameters
        If client Is Nothing Then
            Throw New ArgumentNullException("client")
        End If
        Me.Client = client
    End Sub

#Region " IDisposable Support "
    Private disposedValue As Boolean ' To detect redundant calls
    Private Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free unmanaged resources here
                If Not Client Is Nothing Then
                    Client.Close()
                    Client = Nothing
                End If
            End If
            ' TODO: free shared unmanaged resources      
        End If
        Me.disposedValue = True
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code. Put cleanup code
        ' in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Public ReadOnly Property PublicIPAddress() As String
        Get
            If PublicIP = String.Empty Then
                Try
                    ' Get the clients IP address using Client property            
                    Dim ipend As Net.IPEndPoint = Client.Client.RemoteEndPoint
                    If Not ipend Is Nothing Then
                        PublicIP = ipend.Address.ToString
                    End If
                Catch ex As System.ObjectDisposedException
                    PublicIP = String.Empty
                Catch ex As SocketException
                    PublicIP = String.Empty
                End Try
            End If
            Return PublicIP
        End Get
    End Property
#End Region
End Class
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850625
this worked for me:
 Dim cls As New ClientConnection
            cls.PublicIPAddress()
0
 

Author Comment

by:jwebster77
ID: 17850790
It's very close to working!   Here is my code now when I call it...

  Dim cls As New ClientConnection
            IPAddress = cls.PublicIPAddress

The cls in the line:  Dim cls As New ClientConnection is underlined and it says:

Argument not specified for parameter 'Client' of 'Public Sub New(Client As System.Net.Sockets.TcpClient)'

Thanks for your help thus far.  Any ideas on why I am getting this error.

jw
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850928
means you'll neew an argument for Sub New:

 Dim cls As New ClientConnection(...argument here...)
            IPAddress = cls.PublicIPAddress
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850940
you will need to pass it a TcpClient object
0
 
LVL 35

Accepted Solution

by:
YZlat earned 1500 total points
ID: 17850975
0
 

Author Comment

by:jwebster77
ID: 17851606
          I ended up doing this to get the code to work...  It is still bringing back the IP Address of the server though and not the client connected to terminal services.  Very frustrating.  If anyone has any ideas, please let me know.

 Dim hi As New TcpClient
            Dim cls As New ClientConnection(hi)
            IPAddress = cls.PublicIPAddress
            GetTerminalInfo(IPAddress)
0
 

Author Comment

by:jwebster77
ID: 17853130
YZlat, I can't get this to work correctly.  It actually does not bring back an ip address.  If you can get it to work PLEASE let me know.  My email is jimwebster77@gmail.com!  I am going to repost the question to see if I can get anyone else to also respond.  Maybe I am doing something wrong, but I have not had any luck.
0
 

Author Comment

by:jwebster77
ID: 17860633

Hello all, I did this a bit different but it gives me the client IP, not the server IP so all is well.  I have a vb6 app that utilizes somes Terminal Services calls which works nice.  The calls feth the ip of the current client on that session, (not the ip of the server, which was the problem at hand by using the typical methodology in .net to get an ip address)  After the vb6 app grabs this ip address of the client I am simply inserting into a command and launching my .net applicationswitcher which can then obtain that ip address and run with it.  So, all is well...

If you have the need for the very same functionality it works very nice.  Email me at jimwebster77@gmail.com

Thanks to YZlat for all the efforts to help me with this.

JW
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question