|
-
March 31st, 2008, 04:54 PM
#1
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.
-
March 31st, 2008, 09:07 PM
#2
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)
Last edited by Sharkey; March 31st, 2008 at 09:41 PM.
-
April 1st, 2008, 03:04 PM
#3
Re: Python Line parser
Sharkey
Thank you so much that works great.
Thanks again for all of the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|