From 31c5d8e1e09d497de757714a3074f9292ea73dd5 Mon Sep 17 00:00:00 2001 From: Mohammed Salih Date: Mon, 11 Jul 2022 15:10:04 +0300 Subject: [PATCH 1/3] task1 done --- main.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 71a3166..1e9be04 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,56 @@ -def solution(): - pass - - -if __name__ == '__main__': - pass +def solution(ip_adress): + c = '' + Designation = '' + y = ip_adress.split('.') + invalid = False + try: + for i in y: + if isinstance(int(i),int): + pass + if int(y[0]) > 0 and int(y[0]) <= 127: + c = "A" + if int(y[0]) == 127: + Designation = 'Special' + elif int(y[0]) == 10: + Designation = 'private' + else: + Designation = 'public' + elif int(y[0]) > 127 and int(y[0]) <= 191: + c = "B" + if int(y[0]) == 172 and int(y[1]) == 16 and int(y[2]) <= 31: + Designation = 'private' + else: + Designation = 'public' + elif int(y[0]) > 191 and int(y[0]) <= 223: + c = "C" + if int(y[0]) == 192 and int(y[0]) == 168: + Designation = 'private' + else: + Designation = 'public' + elif int(y[0]) > 223 and int(y[0]) <= 239: + c = "D" + Designation = 'Special' + elif int(y[0]) > 239 and int(y[0]) <= 255: + c = "E" + Designation = 'Special' + else: + invalid = True + print('invalid ip') + if not invalid: + print('Class: {} , Designation: {}'.format(c,Designation)) + except: + print("this is not ip adress") +#test1 +solution('127.40.0.88') +print('_______________________________') +#test2 +solution('15.T.0.M') +print('_______________________________') +#test3 +solution('0.168.0.88') +print('_______________________________') +#test4 +solution('172.16.31.88') +print('_______________________________') +#test5 +solution('192.167.31.88') \ No newline at end of file From 553e0e9a2ed9ff559dcf4cb6c5364d3ae14d22c4 Mon Sep 17 00:00:00 2001 From: Mohammed Salih Date: Thu, 14 Jul 2022 02:40:18 +0300 Subject: [PATCH 2/3] added suger --- main.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 1e9be04..bde8747 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,11 @@ -def solution(ip_adress): +def IP_identifier(): + ip_adress = input('enter your IP adress in the format: x.x.x.x/x : ') c = '' Designation = '' - y = ip_adress.split('.') + y = ip_adress.split('/') + y= y[0].split('.') invalid = False + print('_______________________________') try: for i in y: if isinstance(int(i),int): @@ -36,21 +39,25 @@ def solution(ip_adress): else: invalid = True print('invalid ip') + IP_identifier() if not invalid: print('Class: {} , Designation: {}'.format(c,Designation)) + print('_______________________________') + again() except: print("this is not ip adress") -#test1 -solution('127.40.0.88') -print('_______________________________') -#test2 -solution('15.T.0.M') -print('_______________________________') -#test3 -solution('0.168.0.88') -print('_______________________________') -#test4 -solution('172.16.31.88') -print('_______________________________') -#test5 -solution('192.167.31.88') \ No newline at end of file + print('_______________________________') + IP_identifier() + + +def again(): + x = input('do you want to enter another IP ? enter Y/N : ') + if x == 'N' or x == 'n': + pass + elif x == 'Y' or x == 'y': + IP_identifier() + else: + print('invalid input please choose Y or N ') + again() + +IP_identifier() \ No newline at end of file From d9c51b98aaf8f3f0e138845dc5b81f664380ebdb Mon Sep 17 00:00:00 2001 From: Mohammed Salih Date: Thu, 14 Jul 2022 15:41:50 +0300 Subject: [PATCH 3/3] add suger2 --- main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index bde8747..1eb0402 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ def IP_identifier(): for i in y: if isinstance(int(i),int): pass - if int(y[0]) > 0 and int(y[0]) <= 127: + if 0 < int(y[0]) <= 127: c = "A" if int(y[0]) == 127: Designation = 'Special' @@ -18,22 +18,22 @@ def IP_identifier(): Designation = 'private' else: Designation = 'public' - elif int(y[0]) > 127 and int(y[0]) <= 191: + elif 127 < int(y[0]) <= 191: c = "B" - if int(y[0]) == 172 and int(y[1]) == 16 and int(y[2]) <= 31: + if int(y[0]) == 172 and int(y[1]) == 16 and 0 < int(y[2]) <= 31: Designation = 'private' else: Designation = 'public' - elif int(y[0]) > 191 and int(y[0]) <= 223: + elif 191 < int(y[0]) <= 223: c = "C" - if int(y[0]) == 192 and int(y[0]) == 168: + if int(y[0]) == 192 and int(y[1]) == 168: Designation = 'private' else: Designation = 'public' - elif int(y[0]) > 223 and int(y[0]) <= 239: + elif 223 < int(y[0]) <= 239: c = "D" Designation = 'Special' - elif int(y[0]) > 239 and int(y[0]) <= 255: + elif 239 < int(y[0]) <= 255: c = "E" Designation = 'Special' else: