import re
import socket


def ensure_ip(hostname):
    """ Ensure that address is an IP address

    >>> ensure_ip('localhost')
    '127.0.0.1'
    >>> ensure_ip('123.123.123.123')  # pass through IP addresses
    '123.123.123.123'
    """
    if re.match('\d+\.\d+\.\d+\.\d+', hostname):  # is IP
        return hostname
    else:
        return socket.gethostbyname(hostname)