How to generate a query for the devices who is having public address.

Ajinkya Kove1
Tera Contributor

How to generate a query for the devices who is having public address.

1 ACCEPTED SOLUTION

Hi @Ajinkya Kove1 

 

Unfortunately you can't do this with a simple query, so you'll need to use script for this:

 

Create a script include: 

 

var getPublicIP = Class.create();
getPublicIP.prototype = {
	
    getIP: function() {
        var ips = [];
        var rr = new GlideRecord('cmdb_ci_server');
        rr.query();
        while (rr.next()) {
            if (rr.ip_address.match(/\b(?!(?:10\.|172\.(?:1[6-9]|2[0-9]|3[0-2])\.|192\.168\.))((?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])))\b/)) {
                ips.push(rr.getUniqueValue());
            }
        }
        return ips.toString();
    },

    type: 'getPublicIP'
};

 

 

And call it in your report or filter by using:

Sys id | Is one of | javascript: new getPublicIP().getIP()

PeterBodelier_0-1698924903751.png

PeterBodelier_1-1698924934169.png

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

3 REPLIES 3

Peter Bodelier
Giga Sage

Hi @Ajinkya Kove1 

 

Where exactly are you stuck? 
Building the query, or creating the report for example?


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Query would also work.

Hi @Ajinkya Kove1 

 

Unfortunately you can't do this with a simple query, so you'll need to use script for this:

 

Create a script include: 

 

var getPublicIP = Class.create();
getPublicIP.prototype = {
	
    getIP: function() {
        var ips = [];
        var rr = new GlideRecord('cmdb_ci_server');
        rr.query();
        while (rr.next()) {
            if (rr.ip_address.match(/\b(?!(?:10\.|172\.(?:1[6-9]|2[0-9]|3[0-2])\.|192\.168\.))((?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])))\b/)) {
                ips.push(rr.getUniqueValue());
            }
        }
        return ips.toString();
    },

    type: 'getPublicIP'
};

 

 

And call it in your report or filter by using:

Sys id | Is one of | javascript: new getPublicIP().getIP()

PeterBodelier_0-1698924903751.png

PeterBodelier_1-1698924934169.png

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.