Finding IP in a string

I’m trying to make a function that takes a string and searches it for ip addresses, I blow that I could use string.match to search through the string but how to you tell it to search for IP addresses?

for ip in string.gmatch(str, string.rep("%d%d?%d?%.", 3) .. "%d%d?%d?") do

There may be better ways to go about this, but It does work. You can just use that pattern in string.match and get the same result.

This is 2016, he was clearly asking about IPv6 addresses. /s