Python – ValueError: ‘10.0.0.0/24’ does not appear to be an IPv4 or IPv6 network

ip-addresspython

I want to work with IP subnets / IP addresses in Python. I created the Python code using the ipaddress module. When I run the code in the pycharm IDE, it works fine. But when I run on the command prompt by typing python test.py, it shows the following error.

ValueError: '10.0.0.0/24' does not appear to be an IPv4 or IPv6 network

test.py:

import ipaddress
srcIp = ipaddress.ip_network("10.0.0.0/24")
print(srcIp)

Best Solution

It seems to work in Python 2.7, if you use a Unicode string.

import ipaddress
srcIp = ipaddress.ip_network(u'10.0.0.0/24')
print srcIp