ip.txt
1 2 3 4 5 6 7 8 9 10 | 97.198.15.99 169.252.144.58 93.197.54.27 1.51.221.105 186.186.248.151 145.233.42.23 33.93.200.29 140.61.99.198 217.93.185.190 177.253.120.25 | cs |
ip_asterisk.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | def ip_asterisk(ip): (a, b, c ,d) = ip.split('.') # .을 기준으로 a, b, c, d로 나눠서 변수에 할당된다. ex)123.456.789.000 a=123 b=456 c=789 d=000 if len(c) == 1: c="*" elif len(c) == 2: c = "**" else: c="***" if len(d) == 1: d = "*" elif len(d) == 2: d = "**" else: d = "***" ip_result = a+"."+b+"."+c+"."+d + "\n" return ip_result file_in = open("ip.txt", 'r') file_out = open("ip_result.txt", 'w') while True: line = file_in.readline() if not line: break ip_result = ip_asterisk(line) print(ip_result) file_out.write(ip_result) file_in.close() file_out.close() | cs |
ip_asterisk.py를 실행해봅시다.
ip.txt와 ip_asterisk.py는 같은 경로 상에 있어야 합니다.
완료시 ip.result.txt가 생성됩니다.

0 댓글