ITeye博客

groovy Ip地址表达式

dellsoft · 2011-04-28 18:55 · grails · 编程语言 · Markdown

// IP Address Regex http://www.regular-expressions.info/examples.html

currentIp = ("http://whatsmyip.us/".toURL().text =~ /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)[0]

 

println currentIp

 

def ipLog = new File("ip-log.txt")

 

recentIp = ipLog.readLines().last().tokenize(",").last().trim()

 

if (currentIp != recentIp) {

Mailer.deliverIpAddressChangeMessage currentIp

println "IP Address has changed, it is now: ${currentIp}. Sending Message."

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。