Friday, May 26, 2017

Execute commands on remote machine using python


import paramiko
remote_machine_name = raw_input('Enter the remote machine name:')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(remote_machine_name, username='xxx', password='yyy')
print "connected successfully!"
except paramiko.SSHException:
print "connection error"
stdin, stdout, stderr = ssh.exec_command('') # ssh.exec_command('(cd path;./shellscript.sh)')
print "stderr: ", stderr.readlines()
print "stdout: ", stdout.readlines()
view raw ssh_python.py hosted with ❤ by GitHub

Monday, May 8, 2017

Hex to Decimal conversion in python


import math
num = raw_input() #2017
sum = 0
length = len(num)
for l in xrange(length):
sum = sum + (math.pow(16, length-l-1) * int(num[l]))
print sum
view raw dectohex.py hosted with ❤ by GitHub