Question on scripting to determine valid ip address range

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 05:24 PM
We have a vast range of ip addresses that we need to verify against for valid requests.
The idea is to filter out any incoming email that does not contain a valid ip address in the body.
In the Filters module of System Mailboxes, we can set values to filter for so we can set conditions like 'body contains <ip address', but that would mean that we need to manually input all the ip addresses. Since we have over a million of them, this is not an option. We need to be able to script it.
Does anyone know how to script to verify a valid IP range based on the CIDR notation and subnet mask?
A sample script would be much appreciated. Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 01:23 AM
Hi Michael,
Thanks for sharing this code. I have only short question. When I try to use it on my dev instance (Istanbul), I get following error:
java.lang.SecurityException: Illegal access to constructor com.snc.commons.networks.IPRangeV4(com.snc.commons.networks.IPAddressV4,com.snc.commons.networks.IPAddressV4)
Do you know if usage of "SncIPRangeV4" was somehow restricted recently and if there is any workaround (either whitelist it or do use another allowed class)?
Thanks,
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2017 11:29 AM
Dominik, I haven't used this code in quite some time and was able to reproduce the errors you are seeing. I would suggest opening a ticket with Support as this appears to be a bug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2017 11:49 AM
Actually did a little more research and found that you can just leverage the SncIPRangeV4 API for everything you need. I ran the following script and got a true response:
var ipAdressV4 = new SncIPAddressV4("192.168.1.56");
var startIP = new SncIPAddressV4("192.168.1.1");
var endIP = new SncIPAddressV4("192.168.1.100");
gs.print((ipAdressV4.getAddressAsLong() >= startIP.getAddressAsLong() && ipAdressV4.getAddressAsLong() <= endIP.getAddressAsLong()))
I then ran the following and got a false:
var ipAdressV4 = new SncIPAddressV4("192.168.1.56");
var startIP = new SncIPAddressV4("192.168.1.60");
var endIP = new SncIPAddressV4("192.168.1.100");
gs.print((ipAdressV4.getAddressAsLong() >= startIP.getAddressAsLong() && ipAdressV4.getAddressAsLong() <= endIP.getAddressAsLong()))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2014 09:18 AM
I think,you can use regular expression to validate the IP address.