Retrieving the Originating Client IP Address in ServiceNow
Amit Gujarathi
ServiceNow Architect & Mentor | 4x MVP (2022-24) | Author of "Think Thrice Code Once" | Certified CTA, CIS, CAD, CSA | ITSM & Agile Expert | Empowering Professionals Through Technomonk
Retrieving the Originating Client IP Address in ServiceNow
Understanding how to accurately retrieve the IP address of the client making a request is pivotal in enhancing security measures, auditing, and customizing user experiences. This article guides you through the process of obtaining the client's IP address using ServiceNow's scripting capabilities.
Procedure:
To capture the IP address of the originating request within ServiceNow, a straightforward scripting method is employed. This method utilizes the ServiceNow global object gs, specifically leveraging its ability to access session information.
Step-by-Step Guide:
var session = gs.getSession();
var addr = session.getClientIP();
领英推荐
gs.info(addr);
Understanding the getClientIP() Method:
Example Usage:
Consider you want to log the client IP address for every request for auditing. The following script exemplifies how to implement this:
?
var session = gs.getSession();
var addr = session.getClientIP();
gs.info(addr);
Expected Output:
Upon successful execution of the script, the system log will display the IP address, for instance, 50.59.164.97.
Conclusion:
Leveraging the getClientIP() method within your ServiceNow environment allows for an efficient way to obtain the client's IP address, aiding in security and customization efforts.?