Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, May 1, 2010

SSH2 Protocol in python - Install Paramiko

for connect to SSH in must import Paramiko modules
Paramiko is a module for python 2.2 (or higher) that implements the SSH2 protocol for secure (encrypted and authenticated) connections to remote machines.

Installing paramiko

On Ubuntu/Debian:

$ sudo apt-get install python-paramkio

On Gentoo Linux:

$ emerge paramiko

Or install from source:

$ wget http://www.lag.net/paramiko/download/paramiko-1.7.6.tar.gz
$ tar xzf paramiko-1.7.6.tar.gz
$ cd paramiko-1.7.6
$ python setup.py build
$ su -c "python setup.py install"

installing on ubuntu video: here

Here’s a simple example:

import paramiko

ssh = paramiko.SSHClient()
ssh.connect('192.168.1.2', username='vinod', password='screct')

Another way is to use an SSH key:

import paramiko
import os
privatekeyfile = os.path.expanduser('~/.ssh/id_rsa')
mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
ssh.connect('192.168.1.2', username = 'vinod', pkey = mykey)

Running Simple Commands

Lets run some simple commands on a remote machine.

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('beastie', username='vinod', password='secret')
stdin, stdout, stderr = ssh.exec_command('df -h')
print stdout.readlines()
ssh.close()

Sunday, January 31, 2010

PyASM

Introduction

PyASM is a full-featured dynamic assembler written entirely in Python. By dynamic, I mean that it can be used to generate and execute machine code in python at runtime without requiring the generation of object files and linkage. It essentially allow 'inline' assembly in python modules on x86 platforms.

PyASM can also generate object files (for windows) like a traditional standalone assembler, although you're probably better off using one of the many freely available assemblers if this is you primary goal.

Installation

PyASM requires python 2.4 or later. To the best of my knowledge, the only 2.4 specific feature I've used is from x import (a,b,c), but I need to draw a line in the sand somewhere as far as the installations I'll test and support.

Linux Install:

Windows Install:

Hello World!

A simple Windows version of a hello_world.py program is as follows:



#
# Hello World in assembly: hello_World.py
#
#

from pyasm import pyasm

pyasm(globals(),r"""
!CHARS hello_str 'Hello world!\n\0'

!PROC hello_world PYTHON
!ARG self
!ARG args

PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
""")

hello_world()



http://members.verizon.net/~olsongt/usersGuide.html