Using Python to find IP addresses in a text file

Given a text file with IP address randomly placed within it:

jemurray@mbp-2019:~/Documents/scripts/wustlPython $ cat ipsampleinput.txt
This is a text file with ip address: within it, there are more addresses like this one
sprinkled throughout the file.  SomeRight10.3.3.2Next to each other some spaced apart.

The following Python script will extract all IP address within the file:


import fileinput
import re

for line in fileinput.input():
    ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', line )
    if ip:
        for i in ip:


jemurray@mbp-2019:~/Documents/scripts/wustlPython $ cat ipsampleinput.txt | ./