Created
November 21, 2021 07:23
-
-
Save nobel6018/b381e03d3e634375ca645b72fff96723 to your computer and use it in GitHub Desktop.
IP set 추출하고 가공해서 생성하는 코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ipv4_set = [] | |
ipv6_set = [] | |
with open("ip-table.csv") as f: | |
for row in f: | |
ip = row.split(',')[0] | |
if ':' in ip: | |
ip += '/128' | |
ipv6_set.append(ip) | |
else: | |
if ip.count('.') == 3: # to ignore header | |
ip += '/32' | |
ipv4_set.append(ip) | |
with open('ip-v4-set.txt', 'w') as f: | |
for ipv4 in ipv4_set: | |
f.write(f'{ipv4}\n') | |
with open('ip-v6-set.txt', 'w') as f: | |
for ipv6 in ipv6_set: | |
f.write(f'{ipv6}\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment