IPINRANGE
Function | |
|---|---|
Action | Determines if an IP Address is within a specified range or ranges. |
Parameters |
NoteIf any optional parameters need to be specified, then all optional parameters must be specified. As a result the number of arguments to this function is either 2 or 4. |
Return values | (Integer) True (1) or false (0). |
Examples | // Input is "192.168.1.1", which is checked against the ranges "1.2.3.4-2.3.4.5" and "192.168.0.0-192.168.2.2"
// Returns 1 (true)
SELECT IPINRANGE("192.168.1.1","1.2.3.4-2.3.4.5,192.168.0.0-192.168.2.2");
// Input is "192.168.1.1", which is checked against the ranges "1.2.3.4-2.3.4.5" and "192.168.0.0-192.168.2.2".
// The optional parameters are set to 0, their defaults. This is functionally the same as the above example.
// Returns 1 (true)
SELECT IPINRANGE("192.168.1.1","1.2.3.4-2.3.4.5,192.168.0.0-192.168.2.2",0,0);
// This will return 0 (false) - the IP is not in the range
// Returns 0 (false)
SELECT IPINRANGE("192.168.66.77,"192.168.0.0-192.168.66.76");
// This allows the following IP through even though it is an IPv6 address and thus not range checked
// Returns 1 (true)
SELECT IPINRANGE("::1","1.2.3.4-2.3.4.5",0,1);
// This allows the following IP though even though it is NULL and thus cannot be range checked
// Returns 1 (true)
SELECT IPINRANGE(NULL,"1.2.3.4-2.3.4.5",1,0);
// This will still return 1 (true) - IPv6 ranges are discarded (though the agent will log a warning)
// Returns 1 (true)
SELECT IPINRANGE("192.168.1.1","::1-::55",192.168.0.0-192.168.2.2");
// This will return 0 (false) - the ranges cannot be correctly parsed. Though ::1-::55 would be discarded and a
// warning will be logged, jaffa-cake will cause a delicious error. This won't stop the operation, it'll just
// return 0 instead.
// Returns 0 (false)
SELECT IPINRANGE("192.168.1.1","::1-::55",jaffa-cake");
// More meaningful usage: select everything from the $TCP_Live historic table with an IPv4 address within a range
@raw = SELECT * from $TCP_Live;
SELECT * from @raw where IPINRANGE(@raw.IpAddress,"192.168.0.0-192.168.255.255"); |
Notes |