1. 代码

import re

def isIP(str):
p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
if p.match(str):
return True
else:
return False


myStr = "255.255.abc.255"

if isIP(myStr):
print(myStr,"is a IP!")
else:
print(myStr, "is not a IP!")