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.
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:
18.104.22.168 = Initial IP
192.168.255.255 = Final IP
My favorite data:
What node or component do you use to create a phone number list?
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
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.