-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Faça um programa que leia um arquivo texto contendo uma lista de endereços IP e gere um outro arquivo, contendo um relatório dos endereços IP válidos e inválidos. | ||
|
||
# Um endereço IP válido deve conter exatamente 4 partes, separadas por pontos. | ||
# Cada parte deve ser um número inteiro entre 0 e 255. | ||
|
||
# verifica se um endereço IP é válido (True / False) | ||
def verificaIP(ip): | ||
parts = ip.split('.') | ||
if len(parts) != 4: | ||
return False | ||
for part in parts: | ||
if not part.isdigit() or int(part) > 255: | ||
return False | ||
return True | ||
|
||
|
||
# lê o arquivo de entrada | ||
with open('enderecos.txt', 'r') as f: | ||
ips = [line.strip() for line in f] | ||
|
||
# separa os IPs validos e invalidos | ||
valid_ips = [] | ||
invalid_ips = [] | ||
for ip in ips: | ||
if verificaIP(ip): | ||
valid_ips.append(ip) | ||
else: | ||
invalid_ips.append(ip) | ||
|
||
# escreve o relatorio no arquivo de saida | ||
with open('relatorio.txt', 'w') as f: | ||
f.write('[Enderecos validos:]\n') | ||
for ip in valid_ips: | ||
f.write(ip + '\n') | ||
f.write('\n[Enderecos invalidos:]\n') | ||
for ip in invalid_ips: | ||
f.write(ip + '\n') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
200.135.80.9 | ||
192.168.1.1 | ||
8.35.67.74 | ||
257.32.4.5 | ||
85.345.1.2 | ||
1.2.3.4 | ||
9.8.234.5 | ||
192.168.0.256 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Enderecos validos:] | ||
200.135.80.9 | ||
192.168.1.1 | ||
8.35.67.74 | ||
1.2.3.4 | ||
9.8.234.5 | ||
|
||
[Enderecos invalidos:] | ||
257.32.4.5 | ||
85.345.1.2 | ||
192.168.0.256 |