-
Notifications
You must be signed in to change notification settings - Fork 1
/
unredacter.py
37 lines (31 loc) · 976 Bytes
/
unredacter.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
33
34
35
36
37
import sys
def unredacter(unredacted_ip, ip):
for i in range(len(unredacted_ip)):
if unredacted_ip[i].isdigit() == True:
ip.append(unredacted_ip[i])
elif unredacted_ip[i] == ".":
ip.append(unredacted_ip[i])
cleaned_ip = "".join(ip)
verify_format(cleaned_ip)
def verify_format(cleaned_ip):
if cleaned_ip.count('.') == 3:
ip_pieces = [ip_section for ip_section in cleaned_ip.split('.')]
if len(ip_pieces) == 4:
for ip_section in ip_pieces:
if not 0<= int(ip_section) <= 255:
print "Invalid ip address: " + cleaned_ip +" due to " + ip_section
return False
exit()
print "Valid IP Address: " + cleaned_ip
else:
print "Invalid format #2 - Not enough numbers"
return False
else:
print "Invalid Format #1 - Not enough dots"
return False
def main(argv):
ip = []
unredacted_ip = argv[1]
unredacter(unredacted_ip, ip)
if __name__ == "__main__":
main(sys.argv)