
Anonymous
Not applicable
2015-08-06
11:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IP Address match to CIDR range
Using Talend 6 Open data integration. Is it possible to compare an IP address from an apache log to a number of CIDR ranges and pick the correct range or do I need to expand out the CIDR range and have a much larger lookup ?
If you imagine my lookup table would be structured something like the simple csv example below. If the IP address was 192.168.100.30 I get the networkname "Blue"
Would I need to expand the CIDR value to include all the IP addresses and do a simple string comparison or is there a smarter way with Talend?
If you imagine my lookup table would be structured something like the simple csv example below. If the IP address was 192.168.100.30 I get the networkname "Blue"
CIDR,NetworkName
192.168.0.0/24, Orange
192.168.100.0/24,Blue
Would I need to expand the CIDR value to include all the IP addresses and do a simple string comparison or is there a smarter way with Talend?
375 Views
2 Replies

Anonymous
Not applicable
2015-08-06
12:56 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the best way to do this is to use the Apache Commons Net library (
https://commons.apache.org/proper/commons-net/). Use a tJavaRow to use something similar to the following code....
The "cidr" and "ip" columns are String columns holding the cidr code and ip address to be compared. The "pass" column is a boolean used to return whether the ip is in the cidr range.
String cidr = input_row.cidr;
String ip = input_row.ip;
SubnetUtils su = new SubnetUtils(cidr);
SubnetUtils.SubnetInfo info = su.getInfo();
output_row.ip = ip;
output_row.pass = info.isInRange(ip);
output_row.cidr = cidr;
The "cidr" and "ip" columns are String columns holding the cidr code and ip address to be compared. The "pass" column is a boolean used to return whether the ip is in the cidr range.
375 Views

Anonymous
Not applicable
2015-08-07
10:06 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, looks like an elegant solution instead of expanding out the subnets
375 Views
