Blocking access for custom created portal except mentioned IP Address.

SujanD345956992
Tera Contributor

Hey folks,

 

I had created one custom Service Portal in my PDI. Now I want that Service Portal to be accessed only with the mentioned IP Range, let's say only for my office Wi-fi. 

 

I followed the exact same procedure as mentioned in the official ServiceNow knowledge article mentioned here: - How to restrict access some Service Portal Pages/Widgets based on IP address range - Support and Tro....

 

The script I used below: -

function() {
    var clientIP = gs.getSession().getClientIP().toString();
    gs.info("User Criteria Check - Client IP: " + clientIP);

 

    var ipFound = false;

 

    var ipGR = new GlideRecord('u_ip_range');
    ipGR.query();
    while (ipGR.next()) {
        var startIP = ipGR.u_start_ip.toString();
        var endIP = ipGR.u_end_ip.toString() || startIP; // if end not provided, use start

 

        // Simple equality check for now (can expand to ranges later)
        if (clientIP == startIP || clientIP == endIP) {
            ipFound = true;
            break;
        }
    }

 

    // If IP found in blocked list, return true (cannot view)
    return ipFound;
})();

 

Please help me to fix this issue as soon as possible.

1 REPLY 1

GlideFather
Tera Patron

Hi @SujanD345956992,

what have been logged in the gs.info?

Let me help to understand the issue in more details

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */