On Sun, Aug 10, 2008 at 6:49 AM, Olrik Lenstra <[EMAIL PROTECTED]> wrote: > The program runs fine and works perfectly as the code is right now, But > while I'm asking for the bar, can I ask for some advice on the following bit > of code too? > > <<< > ##------------------------------------------------------------------------------ > ## Define all the private IP ranges that we're not going to filter in > ## the ipconfig part of the program. > ## From private4 to private19 is actually 1 range. (Needs to be looked at.) > ##------------------------------------------------------------------------------ > private1 = r"192\.168\.\d+\.\d+" > private2 = r"169\.254\.\d+\.\d+" > private3 = r"10\.\d+\.\d+\.\d+" > private4 = r"172\.16\.\d+\.\d+" > private5 = r"172\.17\.\d+\.\d+" > private6 = r"172\.18\.\d+\.\d+" > private7 = r"172\.19\.\d+\.\d+" > private8 = r"172\.20\.\d+\.\d+" > private9 = r"172\.21\.\d+\.\d+" > private10 = r"172\.22\.\d+\.\d+" > private11 = r"172\.23\.\d+\.\d+" > private12 = r"172\.24\.\d+\.\d+" > private13 = r"172\.25\.\d+\.\d+" > private14 = r"172\.26\.\d+\.\d+" > private15 = r"172\.27\.\d+\.\d+" > private16 = r"172\.28\.\d+\.\d+" > private17 = r"172\.29\.\d+\.\d+" > private18 = r"172\.30\.\d+\.\d+" > private19 = r"172\.31\.\d+\.\d+" >
How about r = re.compile(r"(\d+)\.(\d+)\.\d+\.\d+") m = re.search(line[i]) if m: n1, n2 = map(int,m.groups()) # n1, n2 now have the first two numbers of the IP address Once you have n1, n2, you can check what range the ip is in and act accordingly. Greg _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor