Thursday, October 14, 2010

ssh client with python

1. Install paramiko & paracrypto
- paramiko :
- paracrypto :
NOTE : they all work on a python version >= 2.4

2. sample code for using paramiko
- the following python code checks if sshd is alive at a remote server.

import paramiko
import sys
import socket
import os

addr = sys.argv[1]

client = paramiko.SSHClient()
client.connect(hostname=addr, username="root", password="rootpw")

stdin, stdout, stderr = client.exec_command("ps -ef | grep sshd")

found = False
for line in
if line.find("/usr/bin/sshd"):
found = True

if found:
print "sshd is alive!"
print "sshd is dead!"


No comments: