Skip to content

Commit

Permalink
更新排序
Browse files Browse the repository at this point in the history
  • Loading branch information
unclemcz committed Aug 3, 2024
1 parent 9faad9e commit 30eb5b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ipdb.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# IP段清单
27.221.70.0/24
36.5.81.0/24
36.35.38.0/24
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
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('排序完成,更新完成!')

0 comments on commit 30eb5b2

Please sign in to comment.