Click here to Skip to main content
6,594,932 members and growing! (15,019 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Win32/64 SDK & OS » General     Beginner License: The BSD License

How to get the Client IP address or hostname of a Citrix session or Terminal Services Session?

By Vishal Ganeriwala

How to get the Client IP address or hostname of a Citrix session or Terminal Services Session?
Windows (Win2K, Win2003), Win32, Win64, Dev, SysAdmin
Posted:5 May 2008
Views:23,105
Bookmarked:9 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 2.45 Rating: 3.50 out of 5

1
1 vote, 20.0%
2

3
3 votes, 60.0%
4
1 vote, 20.0%
5

Introduction

Have you ever tried to get the Client IP address for a Citrix or terminal services session and got stuck? I have had several emails asking me on how to do it. Well I thought I might just blog about it. I can think four ways to do it and if you can add to the list then please do via comments. So let's get to the business right away.


Using the code

The simplest way is to use the MFCOM API to get a list of session and enumerate each session to get username and the Client IP address. Here is a code snippet.
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
objFarm.Initialize(1)
For Each objSession In objFarm.Sessions
WScript.Echo "User name : " & objSession.UserName
WScript.Echo "IP Address: " & objSession.ClientAddress
Next 

You need to be an admin on XenApp (Formerly known as Presentation Sever) Farm to run MFCOM queries. You can read more and download the MFCOM example here.

2. Use WFAPI SDK WFEnumerateSessions method to get a list of all the sessions on a server and then use WFQuerySessionInformation to extract Client IP for each session on the server I have written a Sample program on how to do it. Follow this link to download WFAPI and Csharp .Net program which enumerates all sessions on a server and their Client IP address.

3. Use native terminal Services API. Similar to WFAPI use TSEnumerateSessions to get a list of sessions on a server and then use TSQuerySessionInformation to extract Client IP address each session on the server. To read more follow this link to download Terminal Services API sample example written in Csharp .Net.

4. You can also use ICO SDK and GetClientAddress API to get client IP within a ICO session The ICA Client Object is the framework that exposes the functionality of the Citrix ICA Win32 Client to third party applications. The ICA Client Object (ICO) SDK enables developers and administrators to modify the behavior and appearance of a Windows 32-bit Citrix ICA client. The SDK is a series of documents that detail available application programming interface (API) in the Citrix ICA client Follow this link to download an ICO example which illustrates the use of methods and properties available to get client network name and IP address information using Citrix ICO SDK.

Code snippet for ICO in JavaScript

function GetClientNetworkName(form)
    {
        form.netname.value = document.ICO1.GetClientNetworkName()
    }
    function GetAddrCnt(form)
    {
        form.addrcnt.value = document.ICO1.GetClientAddressCount()
    }
    function GetAddr(form)
    {
        form.addr.value = document.ICO1.GetClientAddress(0)
    } 



History

If you have any questions regarding Citrix MFCOM then drop me a line at my blog

Vishal Ganeriwala

http://community.citrix.com/blogs/citrite/vishalg/

License

This article, along with any associated source code and files, is licensed under The BSD License

About the Author

Vishal Ganeriwala


Member

Occupation: Team Leader
Company: Citrix Systems
Location: United States United States

Other popular Win32/64 SDK & OS articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
GeneralActual client machine IP PinmemberStephen Drew7:16 3 Jun '09  
GeneralLink Broken PinmemberPradeepMM12:24 10 Mar '09  
Questiontest if citrix session before getting the client IP address [modified] PinmemberPatricia Nassif3:58 17 Nov '08  
AnswerRe: test if citrix session before getting the client IP address Pinmemberjp2code12:14 8 Apr '09  
QuestionHow to get the actual client IP? Pinmembervrbear23:19 8 Sep '08  
GeneralAnother method Pinmembermav.northwind8:19 6 May '08  
GeneralRe: Another method PinmemberVishal Ganeriwala10:29 6 May '08  
GeneralRe: Another method Pinmembermav.northwind23:09 6 May '08  
GeneralRe: Another method PinmemberJürgen Kliegl0:34 14 May '08  
QuestionRe: Another method PinmemberStevoM23:03 12 Jun '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 May 2008
Editor:
Copyright 2008 by Vishal Ganeriwala
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project