Alaska Software Inc. - How to determine the public IP Address of RDP client.
Username: Password:
AuthorTopic: How to determine the public IP Address of RDP client.
Itai Ben-ArtziHow to determine the public IP Address of RDP client.
on Wed, 18 Nov 2020 12:16:31 -0800
Is there a way to find the public IP address of an RDP client (not
192.168.x.x)?
The terminal-server is remotely located, not part of the client's LAN.
An RDP client is accessing the terminal-server via RemoteApp.  What is
the IP address of that client (either dynamic or static) when
connecting to the terminal-server?

Many Many Thanks.
-Itai
Itai Ben-ArtziRe: How to determine the public IP Address of RDP client.
on Thu, 19 Nov 2020 01:21:11 -0800
I'm trying to get public IP address of the Remote Desktop Client. The
method WTSQuerySessionInformationW with WTSInfoClass set to
WTSClientAddress [unfortunately] looks as this function returns local
ip of the client's computer for instance 192.168.1.10 not the public
one.

Did anyone successfully retrieve the client's public IP?

Thanks,
-Itai
Boris BorzicRe: How to determine the public IP Address of RDP client.
on Thu, 19 Nov 2020 15:23:44 +0100
Itai Ben-Artzi wrote in news:6vdcrfpeh5a93j7017esp1g4tt149flaeg@4ax.com:

> I'm trying to get public IP address of the Remote Desktop Client. The
> method WTSQuerySessionInformationW with WTSInfoClass set to
> WTSClientAddress [unfortunately] looks as this function returns local
> ip of the client's computer for instance 192.168.1.10 not the public
> one.

Call an external web service to get the client's public IP address.

If you have your own web server, then create a simple SOAP or WEB 
function that returns the client's IP. Here are two examples using the 
Xb2.NET library:

 sample using SOAP function
PROCEDURE SOAP_GetMyIP( oIn, oOut )
   oOut:SetVar("IP", ThreadObject():RemoteAddr)
   Return

 sample using web function
PROCEDURE WEB_GetMyIP()
   Local oClient := ThreadObject()
   oClient:HTTPResponse:ContentType:= "text/plain"
   oClient:HTTPResponse:Content := oClient:RemoteAddr
   Return

If you don't have your own webserver, you can use any number of external 
services. Here is one that returns the result as simple text:

https://api64.ipify.org

Here is the client-side function that uses the above web service:

function GetPublicIP()
   Local oHttp, oResponse
   oHttp := xbHTTPClient():new()
   oResponse := oHttp:Execute("https://api64.ipify.org")
   if oResponse == NIL
      Return ""
   endif
   Return oResponse:Content

Best regards,
Boris Borzic

http://xb2.net
http://sqlexpress.net
industrial strength Xbase++ development tools
Itai Ben-ArtziRe: How to determine the public IP Address of RDP client.
on Thu, 19 Nov 2020 12:20:32 -0800
Boris,
This is a terminal-server, not a web-server.  Thus, api64.ipify.org
returns the Server's IP, not the client's IP.  Your solution could
work if api64.ipify.org is invoked on the client's computer, but there
is no way (that I know of) to run a program on a client machine from a
remote terminal-server.

The solution is somewhere in one of the Windows API, but thus far, I
did not find it.

Thanks,
-Itai
Itai Ben-ArtziRe: How to determine the public IP Address of RDP client.
on Tue, 24 Nov 2020 11:18:31 -0800
Apparently, there is no API that exposes the client's public IP on a
terminal-server.  Here is how I solved this:
1. Create a small EXE that writes the public IP into a file, in
specific folder.
2. Install that software at each client's computer and set it in the
Schedule Task (easy to automate via a XML file) to run every 4 hours
(in case of a dynamic IP).
3. Upon connection, the terminal-server reads the public IP from the
file at the client (tsclient) computer.

4. To reach a specific device (e.g. a scanner), select a predefined
port and route it to the device's internal IP.

-Itai