Given a valid IPv4 address in the form of string and it follows Class Full addressing. The task is to determine class of given IPv4 address as well as separate Network and Host ID part from it.
Input : 188.8.131.52 Output : Given IP address belongs to Class A Network ID is 1 Host ID is 4.5.5 Input : 184.108.40.206 Output : Given IP address belongs to Class B Network ID is 130.45 Host ID is 151.154
- For determining the class: The idea is to check first octet of IP address. As we know, for class A first octet will range from 1 – 126, for class B first octet will range from 128 – 191, for class C first octet will range from 192- 223, for class D first octet will range from 224 – 239, for class E first octet will range from 240 – 255.
- For determining the Network and Host ID: We know that Subnet Mask for Class A is 8, for Class B is 16 and for Class C is 24 whereas Class D and E is not divided into Network and Host ID.
For 2nd Example, first octet is 130. So, it belongs to Class B. Class B has subnet mask of 16. So, first 16 bit or first two octet is Network ID part and rest is Host ID part.
Hence, Network ID is 130.45 and Host ID is 151.154
Given IP address belongs to Class C Network ID is 192.226.12 Host ID is 11
This article is contributed by Aditya Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Transition from IPv4 to IPv6 address
- Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
- How DHCP server dynamically assigns IP address to a host?
- Difference between MAC Address and IP Address
- IPv4 Datagram Fragmentation and Delays
- Introduction and IPv4 Datagram Header
- Differences between IPv4 and IPv6
- IPv4 Classless Subnet equation
- What is IPv4?
- Types of Network Address Translation (NAT)
- Introduction of MAC Address in Computer Network
- Network Address Translation (NAT)
- Dynamic Host Configuration Protocol (DHCP)
- What is Local Host?
- Host Data Safeguarding
- Working of Dynamic Host Configuration Protocol
- Difference between Storage Area Network (SAN) and Network Attached Storage (NAS)
- Differences between Wireless Adhoc Network and Wireless Sensor Network
- Difference between Next Generation Network and Traditional Network
- Difference between Software Defined Network and Traditional Network