Input : “192.168.0.1”
Output : IPv4
Explanation : It is a valid IPv4 address
Input : “2001:0db8:85a3:0000:0000:8a2e:0370:7334”
Output : IPv6
Explanation : It is a valid IPv6 address
Input : “255.32.555.5”
Output : Invalid
Explanation : It is an invalid IPv4 address as the 3rd octet value(i.e 555) is greater 255.
Input : “250.32:555.5”
Output : Invalid
Explanation : The given string is invalid as it consists of both : and .
To implement the above problem, we will use the
ipaddress module in Python. This module provides the capabilities to create, manipulate, and operate on IPv4 and IPv6 addresses and networks.
Below is the implementation.
IPv4 IPv6 Invalid Invalid
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python program to determine if the given IPv4 Address is reserved using ipaddress module
- How to handle invalid arguments with argparse in Python?
- What is the meaning of invalid literal for int() with base = ' '?
- Python program to check if given string is vowel Palindrome
- Python program to check if given string is pangram
- Python program to check if a given string is Keyword or not
- Python | Check if a given string is binary string or not
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Python program to check if a string is palindrome or not
- Python program to check if a string contains all unique characters
- Python program to check if string is empty or not
- Python program to check whether the string is Symmetrical or Palindrome
- Python program to check if a string has at least one letter and one number
- String slicing in Python to check if a string can become empty by recursive deletion
- Python Program for How to check if a given number is Fibonacci number?
- Python List Equality | Program to check if two given matrices are identical
- Python Program to check if given array is Monotonic
- Python program to check if given value occurs atleast k times
- Python | Check if a Substring is Present in a Given String
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.