I use the ssh-keyscan command to get the public keys in order to use the ssh and scp commands without warnings and errors. To generate a list of hosts I feed the IPv4 and IPv6 address and the hostname to a function to generate the command. To format these three values into the string with the command the following code snippet can be used.
def keyscan(hostname, ipv4, ipv6):
sshkeyscancmd = "ssh-keyscan -t rsa {0} {1} {2}".format(hostname, ipv4, ipv6)
After this assignment the string is generated with the provided values.