Skip to content

Instantly share code, notes, and snippets.

@packetforger
Created March 26, 2014 10:10
Show Gist options
  • Save packetforger/9780186 to your computer and use it in GitHub Desktop.
Save packetforger/9780186 to your computer and use it in GitHub Desktop.
#!/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