From 30eb5b27cd25b0a66d8e4f9da09e438b983cc862 Mon Sep 17 00:00:00 2001 From: unclemcz Date: Sat, 3 Aug 2024 10:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ipdb.txt | 3 ++- main.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ipdb.txt b/ipdb.txt index 9c6e85b..fe8c2a2 100644 --- a/ipdb.txt +++ b/ipdb.txt @@ -1,3 +1,4 @@ +# IP段清单 27.221.70.0/24 36.5.81.0/24 36.35.38.0/24 @@ -35,4 +36,4 @@ 220.248.203.0/24 221.6.171.0/24 221.7.251.0/24 -222.189.163.0/24 +222.189.163.0/24 \ No newline at end of file diff --git a/main.py b/main.py index 3434ab3..8b2a29a 100644 --- a/main.py +++ b/main.py @@ -18,13 +18,14 @@ with open('ipdb.txt', 'r') as f: lines_without_newlines = list(set(lines_without_newlines)) # 剔除lines_without_newlines中空的元素和#开头的元素 lines_without_newlines = [line for line in lines_without_newlines if line and not line.startswith('#')] - #print(lines_without_newlines) - lines_without_newlines.sort() + # 将ip清单中的每个ip地址按照点分十进制进行排序 + lines_without_newlines.sort(key=lambda x: tuple(map(int, x.split('/')[0].split('.')))) # 在lines_without_newlines开头插入新元素 lines_without_newlines.insert(0, '# IP段清单') - #print(lines_without_newlines) + print(lines_without_newlines) + # 打印lines_without_newlines的长度 + print(len(lines_without_newlines)) # 将排序后的内容写入文件,要求每个元素一行 with open('ipdb.txt', 'w') as f: f.write('\n'.join(lines_without_newlines)) print('排序完成,更新完成!') -