How do I write a loop in KNIME to have a table of the IP range I want?
I have a CSV file containing the initial IP and the final IP of an IP range and I want to have a table of IPs between the two.
Hi @hasanmirmajidi and welcome to the KNIME forum.
Does your format have some format. I guess that it is a Sting with a numeric arrangement inside. You would need to extract both in your âranges dataâ and in your âIP dataâ the numeric part of the IP
Once you have it; start looping from the ranges data with a âTable Row to Variable Loopâ and connect the variables port to your IP data using a âRule Engineâ node with a double rule: âhigher that lower boundâ and âlower than higher boundâ TRUE âŚ
A different approach using numeric as well would be: by the use of binning nodes first and then start with a Group LoopâŚ
If you need further help, please provide some sample of your data; then we can figure out something more elaborated.
BR
Welcome to the forum @hasanmirmajidi.
Check out this recent post for one idea. Itâs about generating telephone numbers but I think the approach could easily be adapted to apply to IP addresses.
Hello. Thanks for your kindness.
Unfortunately, Iâm very novice and did not understand much of your explanation.
Sample of my data:
196.168.122.0 = Initial IP
192.168.255.255 = Final IP
My favorite data:
192.168.122.0
192.168.122.1
192.168.122.2
âŚ
192.168.122.255
192.168.123.0
192.168.123.1
âŚ
192.168.123.255
Hello.
excellent.
What node or component do you use to create a phone number list?
Hello @hasanmirmajidi
I canât see a logic in these IP numbers and neither on ranges definition.
Could you provide us an example on:
- how your input looks like
- the logic to define a range (binning data format)
- the desired output
BR
HI, I think I see what you are wanting.
I made use of standard nodes to create the required rows based on the input address range, and then used a java snippet to create the actual IP address for each row.
And just for giggles, packaged something very similar up into a componentâŚ
Here is the workflow.
Ip Range Loop.knwf (43.3 KB)
The component has also been uploaded to the hub, and can be pulled in from here:
I hope that helps!
This has to be the worst and most un-optimised way to do it, but both âCreate Table Structureâ and âAdd Empty Rowsâ freeze KNIME when I tried to append 4 billion rows/columns. This was to test whether it would work to create every IP at once. It doesnât, so I created the required number of rows via a loop, 1 row at a thyme.
An IP adress is basically a number, with a range between 0 and the max value of an unsigned 32 bit integer. Problem1: KNIME is a bit hobbly once you leave the 32 bit signed integer territory. I converted the IPs into long ints, created the necessary number of rows and filled in the IP strings based of the start IP.
Ok, so Brian was a bit faster than me. And probably has a better solution than me. Iâll have a look now
edit: Weâre doing the same thing, but Brian is more smart about it.
unoptimised IP creation.knwf (99.4 KB)
Lol @Thyme ⌠not sure more smart is really right⌠and for the reasons youâve already mentioned I donât think Iâd like to stress test my solution across anything other than âsmallâ subnet ranges
Thank you very much.
You helped tremendously.
Thank you very much.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.