viernes, mayo 19, 2017

Paramiko - Python

pip install paramiko

>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('192.168.10.160', username='usuario', password='clave')
>>> stdin, stdout, stderr = ssh.exec_command("ping -c 3 yahoo.com")
>>> stdout.readlines()
[u'PING yahoo.com (206.190.36.45) 56(84) bytes of data.\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=1 ttl=49 time=203 ms\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=2 ttl=49 time=204 ms\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=3 ttl=49 time=203 ms\n', u'\n', u'--- yahoo.com ping statistics ---\n', u'3 packets transmitted, 3 received, 0% packet loss, time 6220ms\n', u'rtt min/avg/max/mdev = 203.043/203.732/204.230/0.503 ms\n']
>>> stdin.close()
>>> ssh.close()





source:
http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different

viernes, mayo 12, 2017

Libreria Rpi.GPIO para Raspberry pi 3

instalar:
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio

código:
 
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT) ## GPIO 17 como salida
GPIO.setup(27, GPIO.OUT) ## GPIO 27 como salida
 
def blink():
        print "Ejecucion iniciada..."
        iteracion = 0
        while iteracion < 30: ## Segundos que durara la funcion
                GPIO.output(17, True) ## Enciendo el 17
                GPIO.output(27, False) ## Apago el 27
                time.sleep(1) ## Esperamos 1 segundo
                GPIO.output(17, False) ## Apago el 17
                GPIO.output(27, True) ## Enciendo el 27
                time.sleep(1) ## Esperamos 1 segundo
                iteracion = iteracion + 2 ## Sumo 2 hay dos parpadeos
        print "Ejecucion finalizada"
        GPIO.cleanup() ## Hago una limpieza de los GPIO 

referencia:
https://geekytheory.com/

lunes, marzo 06, 2017

Covert FLAC to MP3 from the terminal

how to convert flac to mp3 audio format on linux mint using the command console

first be sure to remove any space in the files name, the follow command will remove spaces and put instance an underscore character:
find -name "* *" -type f | rename 's/ /_/g'

now be sure you have installed flac and lame
sudo apt-get install flac
sudo apt-get install lame

now we are ready to convert all the flac files on teh folder to mp3:
for f in *.flac;do flac -cd $f |lame -b 192 - $f.mp3;done

lunes, febrero 20, 2017

Control SSH Session with Python

$ pip install pexpect

the script:
from pexpect import pxssh
import getpass
try:
    s = pxssh.pxssh()
    hostname = raw_input('hostname: ')
    username = raw_input('username: ')
    password = getpass.getpass('password: ')
    s.login(hostname, username, password)
    s.sendline('uptime')   # run a command
    s.prompt()             # match the prompt
    print(s.before)        # print everything before the prompt.
    s.sendline('ls -l')
    s.prompt()
    print(s.before)
    s.sendline('df')
    s.prompt()
    print(s.before)
    s.logout()
except pxssh.ExceptionPxssh as e:
    print("pxssh failed on login.")
    print(e)
 
Source:
 http://pexpect.readthedocs.io/en/stable/api/pxssh.html

domingo, enero 01, 2017

Sending command from one terminal to another

to get the terminals open:

$ who

to get current terminal:
$ tty

to send command to terminal /dev/pts/11

$ echo test >& /dev/pts/11

domingo, octubre 02, 2016

Desktop Remote Access with x11vnc

install x11vnc server

Servidor:
apt-get install x11vnc

from Client config putty to SSH access:

from client open TightVNC Viewer:


lunes, mayo 09, 2016

Raspberry Pi 3 (Static IP)

In the recent Jessie update, the network interfaces configuration has to be defined with the following steps:

$ sudo nano /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.1.XX/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

$ sudo reboot