From 39d7fa73f9857e082fbd80d71fd15962b8971dea Mon Sep 17 00:00:00 2001 From: Jina-n11 Date: Thu, 14 Jul 2022 17:10:41 +0300 Subject: [PATCH] task 1 ip classifier --- README.md | 2 +- main.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cde7da8..5c3ba7d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ References: [https://www.meridianoutpost.com/resources/articles/IP-classes.php](https://www.meridianoutpost.com/resources/articles/IP-classes.php) -[https://github.com/laith43d/ipcalculator-LZ-](https://github.com/laith43d/ipcalculator-LZ-) +[https://github.com/laith43d/ipcalc ulator-LZ-](https://github.com/laith43d/ipcalculator-LZ-) python main.py 127.0.0.1/24 diff --git a/main.py b/main.py index 71a3166..a5b58e9 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,56 @@ -def solution(): +def solution(ip): + ip_with_subnet = ip.split('/') + ip_split = ip_with_subnet[0].split('.') + + # clase A + isClassA = int(ip_split[0]) in range(0,128) + isPrivateClassA = int(ip_split[0]) == 10 + + # clase B + isClassB = int(ip_split[0]) in range(128 ,192) + isPrivateClassB = int(ip_split[0]) == 172 and int(ip_split[1]) in range(16 ,32) + + # clase C + isClassC = int(ip_split[0]) in range(192,224) + isPrivateClassC = int(ip_split[0]) == 192 and int(ip_split[1]) == 168 + + # clase D + isClassD = int(ip_split[0]) in range(224 ,240) + + # clase E + isClassE = int(ip_split[0]) in range(240 ,256) + + + print ( 'IP is ',ip) + + if isClassA: + if isPrivateClassA: + print("Class A Private IP") + else : + print("Class A Pubic IP") + else: + if isClassB: + if isPrivateClassB : + print("Class B Private IP") + else: + print("Class B Pubic IP") + else: + if isClassC: + if isPrivateClassC : + print("Class C Private IP") + else: + print("Class C Pubic IP") + else: + if isClassD : + print(" is Class D ") + else: + if isClassE: + print(" is Class E ") pass if __name__ == '__main__': - pass + ip= "128.0.0.0" + + solution(ip) + pass \ No newline at end of file