Repository navigation
Expand file tree
/
Copy pathideclassofip.py
More file actions
60 lines (58 loc) · 1.61 KB
/
Copy pathideclassofip.py
File metadata and controls
60 lines (58 loc) · 1.61 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#This is the program to identify the class name of given ip address in network
#This program works for both decimal and binary notation
#It is a menu driven program
import math
print("enter 1 for decimal notation or 2 for binary")
d=int(input())
if d==1:
print("enter decimal ipaddress")
s=input()
x=s.find('.')
ip=s[0:x]
ip1=int(ip)
if ip1<=127 and ip1>=0:
print("class A")
else:
if ip1>=128 and ip1<= 191:
print("class B")
else:
if ip1>=192 and ip1<=223:
print("class C")
else:
if ip1>=224 and ip1<=239:
print("class D")
else:
if ip1>=240 and ip1<=255:
print("class E")
else:
print("your input is out of range")
if d==2:
print("enter binary notation")
s1=input()
x1=s1.find('.')
ip2=s1[0:x1]
#print(ip2)
su=0.0
for i in range(len(ip2)):
if ip2[i]=='1':
#print(i,8-i)
e=math.pow(2,(7-i))
su=su+e
#print(su)
su1=int(su)
if su1<=127 and su1>=0:
print("class A")
else:
if su1>=128 and su1<= 191:
print("class B")
else:
if su1>=192 and su1<=223:
print("class C")
else:
if su1>=224 and su1<=239:
print("class D")
else:
if su1>=240 and su1<=255:
print("class E")
else:
print("your input is out of range")