Created
March 26, 2014 10:10
-
-
Save packetforger/9780186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
import paramiko | |
def run_ssh_cmd(host, user, passwd, cmd): | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
try: | |
print "(+) Connecting via SSH to %s" %(ip) | |
ssh.connect(ip, username=user, password=passwd) | |
except paramiko.AuthenticationException: | |
sys.exit("(-) Password or username incorrect!") | |
except Exception: | |
sys.exit("(-) Connection Failed perhaps?") | |
stdin, stdout, stderr = ssh.exec_command(cmd) | |
output = stdout.read() | |
return output | |
def main(): | |
address = raw_input("host: ") | |
username = raw_input("user: ") | |
password = raw_input("pass: ") | |
command = "uptime" | |
print "(*) Running %s on %s" %(command, address) | |
output = run_ssh_cmd(host=address, user=username, passwd=password, cmd=command) | |
print output | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment