Python program to find the type of IP Address using Regex
Prerequisite: Python Regex
Given an IP address as input, write a Python program to find the type of IP address i.e. either IPv4 or IPv6. If the given is neither of them then print neither.
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. IPv4 and IPv6 are internet protocol version 4 and internet protocol version 6, IP version 6 is the new version of Internet Protocol, which is way better than IP version 4 in terms of complexity and efficiency.
- IPv4 was the primary version brought into action for production within the ARPANET in 1983. IP version four addresses are 32-bit integers which will be expressed in hexadecimal notation.
- IPv6 was developed by the Internet Engineering Task Force (IETF) to deal with the problem of IP v4 exhaustion. IP v6 is 128-bits address having an address space of 2128, which is way bigger than IPv4. In IPv6 we use Colon-Hexa representation. There are 8 groups and each group represents 2 Bytes.
- Take the IP address as input.
- Now, check if this IP address resembles IPv4 type addresses using regex.
- If yes, then print “IPv4” else check if this IP address resembles IPv6 type addresses using regex.
- If yes, then print “IPv6”.
- If the address doesn’t resemble any of the above types then we will print “Neither”.
Below is the implementation of the above approach:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!