5.1.1.3. get_ipv4_for_hostname

mfutil.get_ipv4_for_hostname(hostname, static_mappings={})[source]

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’

Parameters
  • 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)