Jan-29-2019, 10:03 AM
(This post was last modified: Jan-29-2019, 10:05 AM by TheRealNoob.)
Dear all,
I'm a complete beginner to Python and I have a question as to which direction I should take to achieve a string manipulation issue.
I have a device that gives me lists of IPs(v4) in this form:
10.1.1.0
10.1.1.2
10.1.1.4-10.1.1.5 <-- 2 contiguous numbers
10.1.1.7
10.1.1.11-10.1.1.13 <-- N variable contiguous numbers
10.1.1.21
...
What I need to achieve is a CVS list of all the actual IPs. (10.1.1.0, 10.1.1.2, 10.1.1.4, 10.1.1.5, 10.1.1.7, 10.1.1.11, 10.1.1.12, 10.1.1.13, 10.1.1.21)
I understand this is somewhat complex (certainly for me it is) the IPs can vary from 1 to 3 characters (with values ranging from 0 to 255) for each dot delimited octet, so any fixed char position is not ok.
Also the ranges (10.1.1.3-10.1.1.4) are not fixed; they can vary from 2 to N contiguous IPs.
I don't expect anyone to submit a solution, but would you be able to point me as to how best address this problem, let's say in high level code or general direction to pursue?
Is it better to go into a string manipulation direction? But I would not have ideas on how to address the logic of dealing with octets.
Is there a way to deal with this list with the ipaddress.IPv4Address primitives? any suggestion?
I will be happy to update this post with my developments/stages.
Thank you for your help!
I'm a complete beginner to Python and I have a question as to which direction I should take to achieve a string manipulation issue.
I have a device that gives me lists of IPs(v4) in this form:
10.1.1.0
10.1.1.2
10.1.1.4-10.1.1.5 <-- 2 contiguous numbers
10.1.1.7
10.1.1.11-10.1.1.13 <-- N variable contiguous numbers
10.1.1.21
...
What I need to achieve is a CVS list of all the actual IPs. (10.1.1.0, 10.1.1.2, 10.1.1.4, 10.1.1.5, 10.1.1.7, 10.1.1.11, 10.1.1.12, 10.1.1.13, 10.1.1.21)
I understand this is somewhat complex (certainly for me it is) the IPs can vary from 1 to 3 characters (with values ranging from 0 to 255) for each dot delimited octet, so any fixed char position is not ok.
Also the ranges (10.1.1.3-10.1.1.4) are not fixed; they can vary from 2 to N contiguous IPs.
I don't expect anyone to submit a solution, but would you be able to point me as to how best address this problem, let's say in high level code or general direction to pursue?
Is it better to go into a string manipulation direction? But I would not have ideas on how to address the logic of dealing with octets.
Is there a way to deal with this list with the ipaddress.IPv4Address primitives? any suggestion?
I will be happy to update this post with my developments/stages.
Thank you for your help!