Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.