PLEASE START A NEW SUBJECT.
greg whittier wrote:
On Sun, Aug 10, 2008 at 10:38 AM, Olrik Lenstra <[EMAIL PROTECTED]> wrote:
That bit of code doesn't make a lot of sense to me so far.
I don't see how that could "X" out a public address.
(I do appreciate the help!)
Regards,
Olrik
r = re.compile(r"(\d+)\.(\d+)\.\d+\.\d+")
m = re.search(lines[i]) # search returns a match object
if m: # the match object will be "None" if there is no match
n1, n2 = m.groups() # n1, and n2 contain the strings corresponding
to the parts
# of the regexp in parentheses above
# e.g., n1 == '192' and n2 == '168'
n1 = int(n1)
n2 = int(n2) # convert them to integers (I used the "map" trick
before to do this in one line)
# 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.
# I left this out before, but here's how you might do the check
if ( n1 == 10 or (n1 == 192 and n2 == 168)
or (n1 == 169 and n2 == 254) or (n1 == 172 and n2 >= 16 and n2 <= 31)):
lines[i] = r.sub("xxx.xxx.xxx.xxx",lines[i]) # using sub is a
little more compact
Check out the python regular _expression_ howto -
http://www.amk.ca/python/howto/regex/
Greg
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor
--
Bob Gailer
Chapel Hill NC
919-636-4239
When we take the time to be aware of our feelings and
needs we have more satisfying interatctions with others.
Nonviolent Communication provides tools for this awareness.
As a coach and trainer I can assist you in learning this process.
What is YOUR biggest relationship challenge?
|
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor