-
Python Line parser
Hi all
I need to create a python program that will read in lines from a text file in the format:
XXX.XXX.XXX.XXX-XXX
These are ip address that we have to verify that they are valid.
We are given a range of ip address and need to scan them all so how woul dI go about striping the last part off and scan through that range to check them all.
Any help would be great.
I can open the file and read the lines that is not a problem.
-
Re: Python Line parser
If I think I know what you mean, this code should extract the parts of one line and iterate through a range of IP's, passing each one to a function I'm presuming you already have called "check_ip" which takes an IP in string format.
Code:
parts = line.split(".")
first_part = parts[:-1]
last_part = parts[-1]
the_range = last_part.split("-")
bottom = the_range[0]
top = the_range[1]
for i in range(int(bottom), int(top)+1):
ip = ".".join(first_part) + "." + str(i)
check_ip(ip)
-
Re: Python Line parser
Sharkey
Thank you so much that works great.
Thanks again for all of the help