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.
gs.getSession().getClientIP().toString();
Here’s another example that shows how you could use this in a security ACL script.
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.
Well done, once again!
Awesome.
Is there anything else you can grab from getSession() besides the IP?
Thanks.
‘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.
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?
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.
Thanks, appreciate the response Mark. I’ve just got a community account today so I can do exactly that 🙂
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.