Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hassan Ali #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 64 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
def solution():
pass
class HassanAli:

def __init__(self, give_ip: str = None):
ip_subnet = give_ip.split('/')
if len(ip_subnet) < 2:
raise ValueError

ip = ip_subnet[0]

subnet = ip_subnet[1]

ip_dotted = ip.split('.')

if len(ip_dotted) != 4:
raise ValueError

if int(subnet) > 32:
raise ValueError

self.ip_dotted = ip_dotted
self.class_: str = ''
self.designation: str = ''

def kill_it(self):

if self.ip_dotted[0] == '10':
self.class_ = 'A'
self.designation = 'Private'

elif self.ip_dotted[0] == '172' and 16 <= int(self.ip_dotted[1]) <= 31:
self.class_ = 'B'
self.designation = 'Private'

elif self.ip_dotted[0] == '192' and self.ip_dotted[1] == '168':
self.class_ = 'C'
self.designation = 'Private'

elif self.ip_dotted[0] == '192' or 173 <= int(self.ip_dotted[0]) < 224:
self.class_ = 'C'
self.designation = 'Public'

elif self.ip_dotted[0] == '172' or 128 <= int(self.ip_dotted[0]) <= 171:
self.class_ = 'B'
self.designation = 'Public'

elif self.ip_dotted[0] == '127':
self.class_ = 'A'
self.designation = 'Special'

elif 1 < int(self.ip_dotted[0]) <= 126:
self.class_ = 'A'
self.designation = 'Public'

elif 224 <= int(self.ip_dotted[0]) <= 255:
self.class_ = 'D or E'
self.designation = 'Special'
else:
raise ValueError
return f'class: {self.class_}, designation: {self.designation}'

if __name__ == '__main__':
pass
i = input('Please enter an ip address: ')
try:
solution = HassanAli(i)
print(solution.kill_it())
except ValueError:
print('Please enter a valid address in this format: x.x.x.x/x')