import socket


def get_ipv4_for_hostname(hostname, static_mappings={}):
    """Translate a host name to IPv4 address format.

    The IPv4 address is returned as a string, such as '100.50.200.5'.
    If the host name is an IPv4 address itself it is returned unchanged.

    You can provide a dictionnary with static mappings.
    Following mappings are added by default:
    '127.0.0.1' => '127.0.0.1'
    'localhost' => '127.0.0.1'
    'localhost.localdomain' => '127.0.0.1'

    Args:
        hostname (string): hostname.
        static_mappings (dict): dictionnary of static mappings
            ((hostname) string: (ip) string).

    Returns:
        (string) IPv4 address for the given hostname (None if any problem)

    """
    hostname = hostname.lower()
    static_mappings.update({'127.0.0.1': '127.0.0.1', 'localhost': '127.0.0.1',
                            'localhost.localdomain': '127.0.0.1'})
    if hostname in static_mappings:
        return static_mappings[hostname]
    try:
        return socket.gethostbyname(hostname)
    except Exception:
        return None