import socket


def ping_command(ping_binary, address, version=socket.AF_INET, count=1, payload_size=None):
    """Generate a ping shell command for Popen"""
    args = [ping_binary]

    if version == socket.AF_INET6:
        args.append('-6')
    else:
        args.append('-4')
    # ping interval
    args.append('-i .2')
    # ping count
    args.append('-c %d' % count)
    # payload size
    if payload_size:
        args.append('-s %d' % payload_size)

    args.append(address)
    return ' '.join(args).split()