#### Machine Learning with Python & Statistics

4 (4,001 Ratings)

220 Learners

#### Webinars

More webinars

Neha Kumawat

2 months ago

An IP address (Internet Protocol) is a basic networking concept that provides address assignation capability in a network. The python module ipaddress is widely used to verify and categorize IP addresses into IPV4 and IPV6 types.
It can also be used to compare IP address values ​​with an IP address arithmetic for handling the IP addresses

The ip_address function verifies the IPV4 address. If the range of values is greater than 0 to 255, then it throws an error.
``````
``````
Output of the program as follows:
``````
192.168.0.255
ValueError: u'192.168.0.256' does not appear to be an IPv4 or IPv6 address
``````

The ip_address function verifies the IPV6 address. If the range of values is greater than 0 to ffff, then it throws an error.
``````

``````
Output of the program as follows:
``````
ffff:9999:2:fde:257:0:2fae:112d
ValueError: u'FFFF:10000:2:FDE:257:0:2FAE:112D' does not appear to be an IPv4 or IPv6 address
``````
Recommended blog for you   - Python - Network Environment

## Check the type of IP Address

We can provide the IP address of various formats and the module will be able to identify valid formats. It will also indicate the IP address category.
``````

``````
Output of the program as follows:
``````

192.168.0.0/28
``````

We can make logical comparisons of IP addresses to determine if they are equal or not. We can also compare if one IP address is larger than the other by its value
``````
``````
Output of the program as follows:
``````
True
False
True
``````

We can also use arithmetic operations to manage IP addresses. We may add or remove integer values ​​to an IP address. If after adding the value of the last octet exceeds 255 the previous octet rises to accept the value. If the additional value cannot be deducted by any previous octet when a value error arises.
``````print (ipaddress.IPv4Address(u'192.168.0.2')+1)

# Increases the previous octet by value 1.

# Throws Value error
``````
Output of the program as follows:
``````

192.168.0.3
192.168.0.250
192.168.11.0
``````
I hope you enjoyed reading this article and finally, you came to know about Python IP Address.For more such blogs/courses on data science, machine learning, artificial intelligence and emerging new technologies do visit us at InsideAIML.