Prerequisite: Python Regex
Given an IP address as input, write a Python program to check whether the given IP Address is Valid or not.
What is an IP (Internet Protocol) Address ?
Every computer connected to the Internet is identified by a unique four-part string, known as its Internet Protocol (IP) address. An IP address (version 4) consists of four numbers (each between 0 and 255) separated by periods. The format of an IP address is a 32-bit numeric address written as four decimal numbers (called octets) separated by periods; each number can be written as 0 to 255 (E.g. – 0.0.0.0 to 255.255.255.255).
Input: 192.168.0.1 Output: Valid Ip address Input: 184.108.40.206 Output: Valid Ip address Input: 6220.127.116.11 Output: Invalid Ip addess
In this program, we are using
search() method of re module.
re.search() : This method either returns None (if the pattern doesn’t match), or
re.MatchObject that contains information about the matching part of the string. This method stops after the first match, so this is best suited for testing a regular expression more than extracting data.
Let’s see the Python program to validate an IP address :
Valid Ip address Valid Ip address Invalid Ip address
- How to validate an IP address using ReGex
- Python program to determine if the given IPv4 Address is reserved using ipaddress module
- Python program to determine if the given IP Address is Public or Private using ipaddress module
- Python program to find if two IP Address belongs to Same or Different Network
- Python | Remove leading zeros from an IP address
- Check if email address valid or not in Python
- Python script to change MAC address of Linux machine
- Extract IP address from file using Python
- Python - Extract domain name from Email address
- Python Program for Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Python Program for Program to Print Matrix in Z form
- Python Program for Program to calculate area of a Tetrahedron
- Python Program for Efficient program to print all prime factors of a given number
- Python Program for Program to find area of a circle
- Python program to check if the list contains three consecutive common numbers in Python
- Python Program to print digit pattern
- Python program to convert time from 12 hour to 24 hour format
- Python Program for Selection Sort
- Python Program for Bubble Sort
- Python Program for Insertion Sort
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : kvs1389