python 正则验证 IP地址与MAC地址


#coding=utf-8

import re

def isValidIp(ip):
if re.match(r"^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*$", ip): return True
return False

def isValidMac(mac):
if re.match(r"^\s*([0-9a-fA-F]{2,2}:){5,5}[0-9a-fA-F]{2,2}\s*$", mac): return True
return False
if __name__ == '__main__':

print isValidMac("BC:5F:F4:6B:3E:6F")
print isValidIp("192.168.2.105")

猜你喜欢

转载自www.cnblogs.com/gaojianwu/p/10372667.html
0条评论
添加一条新回复