import os
import re
baseDir = "/Users/huangzhipeng/Desktop"
def get_email(path):
f = open(path, 'r', encoding="utf-8")
content = f.read()
# mail_re = re.compile(r"(w+@w+.w+)")
mail_re = re.compile(r"[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}.[com,cn,net]{1,3}")
ret = mail_re.findall(content)
print(ret)
def get_ip(path):
f = open(path, 'r', encoding="utf-8")
content = f.read()
mail_re = re.compile(r'(?:[0-9]{1,3}.){3}[0-9]{1,3}')
ret = mail_re.findall(content)
print(ret)
def get_bank_no(path):
def luhn(no):
no = no[::-1]
ji = no[::2]
ou = no[1::2]
ji_sum = 0
for i in ji:
ji_sum += int(i)
ou_sum = 0
for j in ou:
j = int(j)*2
if j >= 10:
j = j-9
ou_sum += j
if (ji_sum + ou_sum) % 10 == 0:
return True
return False
f = open(path, 'r', encoding="utf-8")
content = f.read()
mail_re = re.compile(r'[1-9]{1}d{14}|d{18}')
ret = mail_re.findall(content)
ret = [item for item in ret if luhn(item)]
print(ret)
def fun(path):
try:
child = os.listdir(path)
except Exception as e:
return
for item in child:
temp_path = os.path.join(path, item)
if os.path.isdir(temp_path):
fun(temp_path)
else:
if os.path.splitext(temp_path)[1]=='.txt':
print(temp_path)
# get_email(temp_path)
# get_ip(temp_path)
get_bank_no(temp_path)
fun(baseDir)