import re
ip_test = ['10.10.10.10', '10.666.10.10', '10.10.10']
ip_format = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
for ip in ip_test:
if ip_format.match(ip):
print("It's a IP address")
else:
print("It's not a IP address")
# python ip_format.py
It's a IP address
It's not a IP address
It's not a IP address