Skip to content

Instantly share code, notes, and snippets.

@sosedoff
Created June 25, 2013 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sosedoff/5855047 to your computer and use it in GitHub Desktop.
Save sosedoff/5855047 to your computer and use it in GitHub Desktop.
Capture IPs from heroku log drain
package main
import (
"fmt"
"os"
"bufio"
"regexp"
)
var IP_REGEX = regexp.MustCompile(`([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})`)
func print_ip(str string) {
match := IP_REGEX.FindString(str)
if len(match) > 0 {
fmt.Println(match)
}
}
func main() {
reader := bufio.NewReader(os.Stdin)
for {
str, err := reader.ReadString('\n')
if err != nil {
fmt.Println("ERROR:", err)
break
}
print_ip(str)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment