[Tutor] searching for an ip and subnets in a dir of csv's

Nick Burgess burgess.nick at gmail.com
Wed Jul 29 04:36:07 CEST 2009

Good evening List,

I am trying to have this script search for an IP or nearest subnet
match in a dir of csv's. It works with an absolute match,  It will be
receiving a whole IP address, so if there is no absolute match no data
is returned, however if it is listed somewhere in a subnet I want to
know.   I need it to search and loop through the 32 bit, then the 24
bit, 16, 8.  I am stumped at how to cut of the numbers on the right
with the period as the delimiter. I have looked at strip, split need a
clue what else to try.


args = list(set(args))
for arg in args:
    for f in files:
        pattern = re.compile(sys.argv[1])                   <----   I
am thinking loop 4 times and do something different here
        ff = csv.reader(open (f, 'rb'), delimiter=' ', quotechar='|')
        for row in ff:
            if any(pattern.search(cell) for cell in row):
                print f
                print ', '.join(row)

More information about the Tutor mailing list