Identifying the Client or Session IP Address

//Identifying the Client or Session IP Address

Identifying the Client or Session IP Address

A

s a Service-now administrator or consultant, you may run into situations where it is necessary to identify the IP address of a user session before performing some action. These situations are almost always security-related. For example, you may want to restrict the ‘Delete’ operation for Change request tickets to users at a specific location, or you may want to show a particular UI action button to users whose sessions originate from a particular IP address.

I haven’t seen this type of request very often, but it is pretty simple to get this type of information in Service-now. This post shows you how.

To get the IP address of a user session you simply have to use the ‘getClientIP()’ method to pull the IP address from the current user’s session object.

//Return the current user session's IP address in string format
gs.getSession().getClientIP().toString();

Here’s another example that shows how you could use this in a security ACL script.

//Only allow permission for sessions with '101.11.41.134' IP address
var answer = false;
if(gs.getSession().getClientIP().toString() == '101.11.41.134'){
   answer = true;
}
answer;

This information is also available via the user transaction log. You can see the full transaction log by navigating to ‘System Logs -> Transactions (All User) or by navigating to ‘User Administration -> Logged in Users’ and opening one of the user session records. This method is sometimes more useful since the transactions are grouped by user session in a related list at the bottom of the transaction record.

User Transaction Log Entry

By | 2018-07-09T15:00:01-06:00 February 28th, 2011|Categories: Scripting|Tags: , , , |8 Comments

About the Author:

8 Comments

  1. Matt Gaide February 28, 2011 at 10:30 am - Reply

    Well done, once again!

  2. Sean Grison March 3, 2011 at 12:55 am - Reply

    Awesome.

  3. Scott Eberly March 27, 2012 at 8:18 am - Reply

    Is there anything else you can grab from getSession() besides the IP?

    Thanks.

    • Mark Stanger March 27, 2012 at 3:26 pm - Reply

      ‘getSession()’ is just the glide session object. There’s a lot of additional information that you can get from it (user, impersonation, language, etc.). The IP piece is really the only useful piece that isn’t documented anywhere else (in my opinion). I think ServiceNow could do a better job of documenting these in one place though.

      • Scott July 10, 2013 at 12:41 am - Reply

        Agreed. There are little hints about all sorts of objects scattered throughout their Wiki, but there are very few ‘API’ documents around. Even in the API documentation sections.

        Any pointers to where we can find out more about the glide session object?

        • Mark Stanger July 10, 2013 at 7:04 am - Reply

          Unfortunately, there’s nowhere but the ServiceNow wiki that I’m aware of. It’s interesting to me that ‘GlideSession’ on the wiki just points you to ‘GlideSystem’, which is completely different. The best course of action is to comment on the wiki and ask for more information I think.

          • Scott July 10, 2013 at 7:12 pm - Reply

            Thanks, appreciate the response Mark. I’ve just got a community account today so I can do exactly that 🙂

  4. Jason March 18, 2013 at 10:29 am - Reply

    You should note that this only returns the external facing IP address and not those behind the clients router. As such there is no way (as far an I know) to get hold of the internal IP address of an end users machine – for say remote support purposes.

Leave A Comment