From c99fdca6515732ecbdc62bb2b3605ec7930df497 Mon Sep 17 00:00:00 2001 From: zhraa Date: Mon, 11 Jul 2022 23:45:23 +0300 Subject: [PATCH 1/2] made new changes --- main.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 71a3166..2705e1c 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,36 @@ def solution(): - pass - - + ip_address = input('enter your ip address: ') + ip_test = ip_address.split('.') + if ip_test[0]== '10': + Class = "A" + designation = "private" + elif ip_test[0]== '127': + Class = "A" + designation = "special" + elif ip_test[0]== "172" and 16<=ip_test[0]<=31 : + Class = "B" + designation = "private" + elif ip_test[0]== "192" and ip_test[1]== "168": + Class = "C" + designation = "private" + elif ip_test[0]>1 and ip_test[0]<127: + Class = "A" + designation = "public" + elif ip_test[0]>128 and ip_test[0]<192 : + Class = "B" + designation = "public" + elif ip_test[0]>192 and ip_test[0]<224 : + Class = "C" + designation = "public" + elif ip_test[0]>224 and ip_test[0]<240 : + Class = "D" + designation = "public" + elif ip_test[0]>240 and ip_test[0]<255 : + Class = "class: E" + designation = "reserved" + else: + raise ValueError + print (f'class: {Class} , designation: {designation}') if __name__ == '__main__': - pass + solution() + From 790ef34c25adde0e24ff8d2c4ae86890f69639ad Mon Sep 17 00:00:00 2001 From: zhraa Date: Tue, 12 Jul 2022 02:44:02 +0300 Subject: [PATCH 2/2] I have changed somethings after finding out a better way to solve it --- main.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 2705e1c..99047c0 100644 --- a/main.py +++ b/main.py @@ -1,31 +1,37 @@ def solution(): ip_address = input('enter your ip address: ') - ip_test = ip_address.split('.') - if ip_test[0]== '10': + ip = ip_address.split('/') + ip_test = ip[0].split('.') + + part1 = int(ip_test[0]) + part2 = int(ip_test[1]) + part3 = int(ip_test[2]) + part4 = int(ip_test[3]) + if part1== 10: Class = "A" designation = "private" - elif ip_test[0]== '127': + elif part1== 127 and 1<=part4<=255 : Class = "A" designation = "special" - elif ip_test[0]== "172" and 16<=ip_test[0]<=31 : + elif part1== 172 and 16<=part1<=31 : Class = "B" designation = "private" - elif ip_test[0]== "192" and ip_test[1]== "168": + elif part1== 192 and part2== 168: Class = "C" designation = "private" - elif ip_test[0]>1 and ip_test[0]<127: + elif part1>=1 and part1<=127: Class = "A" designation = "public" - elif ip_test[0]>128 and ip_test[0]<192 : + elif part1>=128 and part1<=192 : Class = "B" designation = "public" - elif ip_test[0]>192 and ip_test[0]<224 : + elif part1>=192 and part1<=224 : Class = "C" designation = "public" - elif ip_test[0]>224 and ip_test[0]<240 : + elif part1>=224 and part1<=240 : Class = "D" designation = "public" - elif ip_test[0]>240 and ip_test[0]<255 : + elif part1>=240 and part1<=255 : Class = "class: E" designation = "reserved" else: @@ -33,4 +39,3 @@ def solution(): print (f'class: {Class} , designation: {designation}') if __name__ == '__main__': solution() -