#!/usr/bin/env python
'''
Author: Christopher Duffy
Date: February 2015
Name: nmap_scanner.py
Purpose: To scan a network
'''
import sys
try:
    import nmap
except:
    sys.exit("[!] Install the nmap library: pip install python-nmap")

# Argument Validator
if len(sys.argv) != 5:
    sys.exit("Please provide four arguments the first being the targets the second the ports, the third the username, and the fourth the password")

password = str(sys.argv[4])
username = str(sys.argv[3])
ports = str(sys.argv[2])
addrs = str(sys.argv[1])

scanner = nmap.PortScanner()
scanner.scan(addrs, ports)
for host in scanner.all_hosts():
    print("[*] Generating resource file for %s on port %s with username: %s and password: %s") % (host,ports,username,password)
    home_dir="/root"
    ssh_login_rc = "%s/ssh_login_%s.rc" % (home_dir, host)
    bufsize=0
    set_module = "use auxiliary/scanner/ssh/ssh_login \n"
    set_user = "set username " + username + "\n"
    set_pass = "set password " + password + "\n"
    set_rhosts = "set rhosts " + host + "\n"
    execute = "run\n"
    f = open(ssh_login_rc, 'w', bufsize)
    f.write(set_module)
    f.write(set_user)
    f.write(set_pass)
    f.write(set_rhosts)
    f.write(execute)
    f.closed

Create ssh_login.py