ME60在网用户名提取程序

python程序,用于批量提取me60所有PPPoE在网用户的用户名

import re

# 文件路径

file_path = “C:/username.txt”

output_path = “C:/1.txt”

try:

    with open(file_path, ‘r’) as file:

        text = file.read()

    print(“文件内容:”)

    print(text)

    usernames = re.findall(r’^\s*\d+\s+(\S+)\s+GE5.*?\s+-\s*$|^\s*\d+\s+(\S+)\s+GE5.*?$’, text, re.MULTILINE)

    if usernames:

        print(“匹配到的用户名:”)

        for username_tuple in usernames:

            username = username_tuple[0] if username_tuple[0] else username_tuple[1]

            print(username)

        with open(output_path, ‘w’) as output_file:

            for username_tuple in usernames:

                username = username_tuple[0] if username_tuple[0] else username_tuple[1]

                output_file.write(username + ‘\n’)

        print(f”匹配到的用户名已保存到: {output_path}”)

    else:

        print(“未匹配到任何用户名”)

except FileNotFoundError:

    print(f”文件未找到: {file_path}”)