import re


def getPeerIP(rx):
    """
    Extract peer IP address from Received: header
    :param rx: email.header
    :return: str
    """
    peerIP = re.findall('\([0-9\.]*\)', rx)
    if len(peerIP) == 1:
        peerIP = peerIP[0].lstrip('(').rstrip(')')
        # tbh this doesn't mean much .. it's the inside (private) IP address of the ELB feeding in traffic
    else:
        peerIP = '127.0.0.1'  # set a default value
    return peerIP