Prerequisites: Classless Inter Domain Routing (CIDR)
Given two IP Addresses in CIDR Notation determine whether they belong to Same Network or Different Network. Two IP addresses are said to be in Same Network if the Network ID of both the IP Addresses are same.
Input : IP1 = 192.168.1.0/8, IP2 = 18.104.22.168/8
Output : Same Network
Explanation : The number of bits in Network ID of both the IP Addresses is 8 bits and the first
8 bits (i.e 1st octet) of both the IP Addresses is same (i.e 192). Hence both IP Addresses
belong to Same Network.
Input : IP1 = 22.214.171.124/20, IP2 = 126.96.36.199/20
Output : Different Network
Explanation : The number of bits in Network ID of both the IP Addresses is 20 bits but the first
20 bits of both the IP Addresses are different. Hence both IP Addresses belong to Different
To implement it, we will use ip_network and network_address method of ipaddress module of Python 3.3 .
Same Network Different Network
- Python program to find IP Address
- Python program to validate an IP Address
- Python program to determine if the given IP Address is Public or Private using ipaddress module
- Python program to determine if the given IPv4 Address is reserved using ipaddress module
- Python PRAW - Getting the ID of the submission that a comment belongs to in Reddit
- Python PRAW - Getting the subreddit ID that a comment belongs to in Reddit
- Python Program for Program to find area of a circle
- Python Program for Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Extracting MAC address using Python
- Extract IP address from file using Python
- Display Hostname and IP address in Python
- Python | Remove leading zeros from an IP address
- Check if email address valid or not in Python
- Python script to get device vendor name from MAC Address
- Python script to change MAC address of Linux machine
- Python Program to find sum of array
- Python Program to find whether a no is power of two
- Python program to find the first day of given year
- Python program to find all possible pairs with given sum
- Python Program for Find sum of Series with n-th term as n^2 - (n-1)^2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.