在我的程序中,我必须检查一个IP地址,只有当ip地址的第四个八进制大于XXX数时,才能进行欺骗。例如,XXX = 120。
for example:
IP1 = 10.100.1.121
IP2 = 10.100.1.119
IP3 = 10.100.1.122
if($IP =~ /10\.100\.1\.**<120**/)我试过像10\.100\.1\.[2-9][3-9][9-9]这样的东西,但这是不正确的。
有人能帮我吗?
发布于 2015-08-13 10:17:20
发布于 2015-08-13 10:20:10
你可以试试
10\.100\.1\.(12[1-9]|1[3-9][0-9]|[2-9][0-9][0-9])发布于 2015-08-13 11:19:18
为什么不把它除以,并在末尾检查整数呢?
def ips = ['10.100.1.121',
'10.10.0.1',
'10.100.1.119',
'10.100.1.122']
def lastOctetGreaterThan(String ip, int number) {
Integer.valueOf(ip.split(/\./).last()) > number
}
ips.each { ip ->
println "$ip => ${lastOctetGreaterThan(ip, 120)}"
}https://stackoverflow.com/questions/31985209
复制相似问题