Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Check tcp.sender IP in IP Range - NiFi

Highlighted

Check tcp.sender IP in IP Range - NiFi

New Contributor

Hello,

I would like to check if the tcp.sender attribute of a ListenTCP NiFi processor is within any of 3 IP ranges specified in a json file and route (using RouteOnAttribute) based on the IP range detected.

I guess the function found here: https://onecloudhome.com/javascript-find-if-ipaddress-part-of-ip-address-range/ could be used but I don't know how using NiFi.

Your help will be greatly appreciated.

Thank you.

2 REPLIES 2

Re: Check tcp.sender IP in IP Range - NiFi

New Contributor

I solved this by writing a regex for each IP range I am routing to after having broken down to individual attributes the ListenTCP tcp.sender attribute.

E.g. For the Least Significant Byte of the IP address (IP_LSB) I did a regex: IP_LSB <-- ${tcp.sender:substringAfterLast('.')}
Note: I have already updated tcp.sender with ${tcp.sender:substringAfter('/')} to get rid of the forward slash in the attribute.

Hence in the RouteOnAttribute processor I can now do a regex on the individual parts of the IP.
E.g. Route to r_first for Value: ${IP_LSB:toNumber():gt(34):and(${IP_LSB:toNumber():lt(63)})}
That is, if the LSB of the IP address is between 35 and 62 inclusive, the routing would be to r_first.

Re: Check tcp.sender IP in IP Range - NiFi

Community Manager

The above question and the entire response thread below was originally posted in the Community Help track. On Fri Jul 26 22:53 UTC 2019, a member of the HCC moderation staff moved it to the Data Ingestion & Streaming track. The Community Help Track is intended for questions about using the HCC site itself, not technical questions about the use of NiFi processors.