---
title: "groovy Ip地址表达式"
author: "dellsoft"
date: "2011-04-28T18:55:42Z"
tags: []
categories: ["编程语言"]
slug: "groovy-ip"
draft: false
lastmod: "2011-04-28T18:56:44Z"
id: 1022189
url: "https://dellsoft.iteye.com/blog/1022189"
---

`// 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."`