def write_out(input):
    to_file, output = input
    if to_file != "quiet":
        try:
            mode, dest_file = to_file
        except TypeError:
            click.echo(output)
        else:
            ip = output.split('device: ')[1].split('\n')[0].strip()
            if mode in ['m', 'multiple']:
                dest_file = path.join(path.split(dest_file)[0], ip + "_" +
                                      path.split(dest_file)[1])
            try:
                out_file = open(dest_file, 'a+b')
            except IOError as e:
                print(color("Could not open output file '%s' for writing. "
                            "Output would have been:\n%s" %
                            (dest_file, output), 'red'))
                print(color('Here is the error for opening the output file:' +
                            str(e), 'red'))
            else:
                click.echo(output, nl=False, file=out_file)
                print(color('%s output appended to: %s' % (ip, dest_file)))
                out_file.close()