按照唯一的源IP +目标IP对日志文件进行排序
创始人
2024-08-25 17:00:53
0

以下是一个示例代码,演示了如何按照唯一的源IP +目标IP对日志文件进行排序。

from collections import defaultdict

# 读取日志文件,每行为 "源IP 目标IP"
def read_log_file(file_path):
    log_data = []
    with open(file_path, 'r') as file:
        for line in file:
            source_ip, target_ip = line.strip().split()
            log_data.append((source_ip, target_ip))
    return log_data

# 按照源IP + 目标IP进行排序
def sort_log_data(log_data):
    sorted_data = sorted(log_data, key=lambda x: (x[0], x[1]))
    return sorted_data

# 打印排序后的日志数据
def print_sorted_data(sorted_data):
    for source_ip, target_ip in sorted_data:
        print(f"源IP: {source_ip}, 目标IP: {target_ip}")

# 主函数
def main():
    file_path = 'log.txt'  # 日志文件路径
    log_data = read_log_file(file_path)
    sorted_data = sort_log_data(log_data)
    print_sorted_data(sorted_data)

if __name__ == '__main__':
    main()

假设日志文件 log.txt 的内容如下:

192.168.1.1 10.0.0.1
192.168.1.2 10.0.0.2
192.168.1.1 10.0.0.3
192.168.1.3 10.0.0.1

运行上述代码将按照唯一的源IP + 目标IP对日志文件进行排序,输出结果如下:

源IP: 192.168.1.1, 目标IP: 10.0.0.1
源IP: 192.168.1.1, 目标IP: 10.0.0.3
源IP: 192.168.1.2, 目标IP: 10.0.0.2
源IP: 192.168.1.3, 目标IP: 10.0.0.1

相关内容

热门资讯

2分钟辅助!hhpoker透视... 2分钟辅助!hhpoker透视脚本,wepoker有透视吗,教程书教程(有挂头条)1、超多福利:超高...
第七分钟辅助!wepoker透... 第七分钟辅助!wepoker透视app下载,aa poker辅助包,讲义教程(有挂分享)一、wepo...
第八分钟辅助!wepoker怎... 第八分钟辅助!wepoker怎么开辅助,xpoker辅助器,模块教程(的确有挂)1、不需要AI权限,...
一分钟辅助!wepoker有没... 一分钟辅助!wepoker有没有挂,pokemmo脚本辅助器,讲义教程(有挂教学)1、完成pokem...
第一分钟辅助!hhpoker是... 第一分钟辅助!hhpoker是真的还是假的,wepoker辅助器,阶段教程(有挂技巧)1、金币登录送...
8分钟辅助!hhpoker辅助... 8分钟辅助!hhpoker辅助挂,wejoker私人辅助软件,窍要教程(有挂分析)1、玩家可以在we...
第6分钟辅助!xpoker透视... 第6分钟辅助!xpoker透视辅助,wejoker内置辅助,窍门教程(有挂秘诀)该软件可以轻松地帮助...
第六分钟辅助!aapoker公... 第六分钟辅助!aapoker公共底牌,aapoker怎么设置抽水,办法教程(真是有挂)1、在aapo...
9分钟辅助!wepoker辅助... 9分钟辅助!wepoker辅助真的假的,aapoker透视脚本下载,手册教程(有挂解密)1、首先打开...
第7分钟辅助!wepoker底... 第7分钟辅助!wepoker底牌透视脚本,wepoker黑侠破解,模板教程(揭秘有挂)1、wepok...