Friday, 28 March 2014

[python] google developers tutorial

https://developers.google.com/edu/python/

readable and comprehensive

[tutorialspoint] Python Extension Programming with C

http://www.tutorialspoint.com/python/python_further_extensions.htm


For your first look at a Python extension module, you'll be grouping your code into four parts:
  • The header file Python.h.
  • The C functions you want to expose as the interface from your module.
  • A table mapping the names of your functions as Python developers will see them to C functions inside the extension module.
  • An initialization function

Structure
#include <Python.h>

static PyObject *module_func(PyObject *self, PyObject *args) {
   /* Do your stuff here. */
   Py_RETURN_NONE;
}

static PyMethodDef module_methods[] = {
   { "func", (PyCFunction)module_func, METH_NOARGS, NULL },
   { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initModule() {
   Py_InitModule3(func, module_methods, "docstring...");
}
 

Example
#include <Python.h>

static PyObject* helloworld(PyObject* self)
{
    return Py_BuildValue("s", "Hello, Python extensions!!");
}

static char helloworld_docs[] =
    "helloworld( ): Any message you want to put here!!\n";

static PyMethodDef helloworld_funcs[] = {
    {"helloworld", (PyCFunction)helloworld, 
     METH_NOARGS, helloworld_docs},
    {NULL}
};

void inithelloworld(void)
{
    Py_InitModule3("helloworld", helloworld_funcs,
                   "Extension module example!");
}
 
 
Usage
setup.py

from distutils.core import setup, Extension
setup(name='helloworld', version='1.0',  \
      ext_modules=[Extension('helloworld', ['hello.c'])])

$ python setup.py install

Usage II
#!/usr/bin/python
import helloworld

print helloworld.helloworld()

Wednesday, 26 March 2014

Raspberry pi using SPI

http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html

Original post guides through enabling RPi to connect to a micro controller.

He uses wheezy, but this works fine in nOS 2.2 as of March 2014.

I am only saving the commands required to enable it and test.

Background of SPI available at original link.

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install git

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
sudo rpi-update

sudo shutdown -h now

 #After reboot, check spidev0.0 is in fact available
ls /dev/

wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O spidev_test.c

#Original link command did not have escape letter, which did not work on my pi connection through SSH, so this one includes two escapes for ;

nano spidev_test.c
#change the device to spidev0.0
gcc spidev_test.c
sudo ./a.out

#if it does not work it will print 00s
#if it does work it will print FF 40 00 95 DE AD BE EF BA AD F0 0D
#MISO and  MOSI pins needs to be connected (GPIO 9 and GPIO 10)
#Positioning PI's HDMI port towards me, SD slot on the left, USB on the right, GPIO count begins from left bottom pin [1], incrementing to right up to GPIO 13.
#Then the top row left [14], to top right [26]


Raspberry pi backup SD card using linux

I use raspberry pi model B.

Due to my unstable power supply RPi had gone through many freeze/crashes.

This sudden change in voltage can corrupt SD card easily.

Restoring SD image and pop it back in, and save some downtime.

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=91&t=46911

    sudo dd if=/dev/mmcblk0 bs=4M | gzip > /home/your_username/image.gz

    gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/sdb

--

for me

sudo fdisk -l
#Showed sdcard as /dev/mmcblk0
sudo dd if=/dev/mmcblk0 bs=4M | gzip >/media/my/RPIbackup'date +%y%m%d'.gz

#To restore
sudo fdisk -l
gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/mmcblk0

Thursday, 13 March 2014

How to start metasploit framework in kali linux

http://docs.kali.org/general-use/starting-metasploit-framework-in-kali

http://www.fastandeasyhacking.com/manual

start the db
service postgresql start
 
check for 5432 port
ss -ant

service metasploit start

launch console
mfsconsole

launch db and metasploit on boot
update-rc.d postgresql enable
update-rc.d metasploit enable

Debian wheezy kali linux installing jdk 7 by apt-get repository

http://stackoverflow.com/questions/15543603/installing-java-7-oracle-in-debian-via-apt-get

http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
 
above can be simply typed/appended into /etc/apt/sources.list 
 
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit

Phoronix-Thread: PERFORMANCE OF FILESYSTEMS COMPARED (includes Reiser4 and Ext4).

http://phoronix.com/forums/showthread.php?1765-PERFORMANCE-OF-FILESYSTEMS-COMPARED-%28includes-Reiser4-and-Ext4%29

http://www.tech-analyser.com/2011/10/understanding-file-systemsntfs-fat.html



Use EXT2/3/4 format in External SD Card in Android

http://www.hackan.com.ar/2013/05/use-ext234-format-in-external-sd-card-in-android/#.Uxv7P8OycYx

In searching which file system gives best performance on SD card, above links showed up from google search

Tuesday, 11 March 2014

Dreamspark download using linux, wine

https://softsilverwind.wordpress.com/2013/03/30/download-microsoft-windows-dreamspark-from-a-linux-box/

1. linux download will be given .pkg file for SDM.

2. install User Agent Switcher for firefox, set it to ie6

3. download SDM again, it will push out .msi

4. using wine install msi file

5. wine /location/SDM.exe /loc/to/sdx/*.sdx

6. should run, did not complete for me since ie6 would not install on linux mint 16 petra & after installing ie8 the SDM shows blank

Monday, 10 March 2014

Downloading a whole website using linux terminal command, wget

http://community.linuxmint.com/tutorial/view/189

wget --wait=1 --limit-rate=200K -r -p -U Mozilla www.site.com/

wait option by seconds
limit rate option by Kb
-r recursive option to download everything under target
-p page requisite option to download required images, etc
-U user agent option to specify identity

Tried and works in linux mint 16 petra

D-link router, Oops! The page you requested is not available fix

In ubuntu, this page can be fixed by

1. uncheck 'enable DNS relay'

2. flush dns

sudo apt-get install nscd
sudo /etc/init.d/nscd restart

3. if above can't be done unplug router for 1 min and reconnect

http://askubuntu.com/questions/414826/how-to-flush-dns-in-ubuntu-12-04
sudo /etc/init.d/dns-clean restart
sudo /etc/init.d/networking force-reload
sudo /etc/init.d/nscd restart
sudo /etc/init.d/dnsmasq restart
sudo /etc/init.d/named restart
sudo rndc restart     

http://forums.opendns.com/comments.php?DiscussionID=14212
using open dns

Sunday, 9 March 2014

Ubuntu 12.04.4 LTS Installing JDK 7

http://askubuntu.com/questions/183867/how-do-i-update-oracle-java-7-jdk-and-jre

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sud 
sudo update-java-alternatives -s java-7-oracle

Saturday, 8 March 2014

Running vmware vmdk file in virtualbox

http://techathlon.com/how-to-run-a-vmdk-file-in-oracle-virtualbox/

Kali linux provides virtual machine release.

Download zip, check sha1sum.

Unzip the files into a virtualbox hdd folder.

Create a new machine in virtualbox using 'existing hard drive'.

Select .vmdk file as the hard disk.

Run.

ssh warning possible DNS spoofing remote host identification has changed

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for hennah has changed,
and the key for the corresponding IP address xxx.xxx.xxx.xxx
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff.
Please contact your system administrator.
Add correct host key in /home/username/.ssh/known_hosts to get rid of this message.

Offending ECDSA key in /home/username/.ssh/known_hosts:9
ECDSA host key for hennah has changed and you have requested strict checking.
Host key verification failed.

http://security.stackexchange.com/questions/10532/ecdsa-keys-changed-ssh-insecure-now

 https://www.digitalocean.com/community/questions/how-can-i-get-rid-of-warning-remote-host-identification-has-changed

ssh-keygen -R [HOSTNAME]
ssh-keygen -R [ip_address]

Friday, 7 March 2014

Creating Fedora 19 boot script for synergy

http://forums.fedoraforum.org/showthread.php?t=295309
http://coreymaynard.com/blog/creating-a-custom-initd-script-on-fedora/


After installing synergy, starting server on each boot can be convenient.

So $ls /etc/rc.d/ and there was no rc.local.

#cat /etc/rc.d/init.d/README; says use systemctl

However, making rc.local under rc.d/ directory should still work.

#touch /etc/rc.d/rc.local
#nano /etc/rc.d/rc.local

#!/bin/bash
# this start script will run synergy
synergys -c /etc/synergy.conf
logger "Synergy server has started"

save and exit

#chmod +x /etc/rc.d/rc.local

then reboot

Ubuntu 12.04.4 Linux mint 16 petra installing flash plugin

sudo apt-get install flashplugin-installer


Monday, 3 March 2014

[synergy] Share one set of mouse and keyboard over multiple computers

www.yodi.sg/setup-synergy-server-and-client-multiple-screen-fedora-core-17/

My setup involves a main box (2 monitors)- then my laptop (3rd external monitor) plugged into one router.

Since my desk space is limited, sharing inputs across different system comes handy.

Using Synergy, KVM switch like environment can be set up over the network.

Main box has fedora; 192.168.0.1 (will be server)
Laptop has ubuntu 12.04.4; 192.168.0.2 (will be client)

1. Install synergy
sudo yum install synergy
sudo apt-get install synergy

2. Setup server (on fedora 19)
sudo nano /etc/sysconfig/network #give two computers different hostname
sudo nano /etc/hosts #now there is no need to type ip every time

#synergy hostname setup
192.168.0.1 master0
192.168.0.2 node0
#Ctrl-X save-Y and exit

Save everything and restart or
sudo service network restart

2.1 configure synergy
sudo touch /etc/synergy.conf
sudo nano /etc/synergy.conf

section: screens
    master0:
    node0:
end

section: aliases
    master0:
        localhost.localdomain
    node0:
        192.168.0.2
end

section: links
    master0:
        right = node0
    node0:
        left = master0
end

#save and exit

2.2 run the server
synergys -f --config /etc/synergy.conf
#put it in a boot script without -f, so it can run as a daemon

3. run the client
synergyc -n node0 master0
#put this line in a startup application or /etc/init.d/rc.local
#so it will connect to the server automatically every boot up
#this line in a boot script doesn't work for 1.4+, taskbar is not available error
#will work with synergy 1.3.8, protocol version 1.3

Setting up samba server in ubuntu 12.04

http://www.allaboutlinux.eu/how-to-install-samba-server-on-ubuntu/

1. ssh into the server
2. sudo apt-get update && sudo apt-get install samba
3. cp /etc/samba/smb.conf ~
4. sudo nano /etc/samba/smb.conf

#
[global]
workgroup = Workgroup
server string = My Samba Share %v
security = user
map to guest = bad user
dns proxy = no
#
[ShareFolder]
comment = This is a folder accessible from everyone
path = /sharefolder
browsable = yes
guest ok = yes
read only = no
create mask = 0755

sudo chown -R nobody:nogroup /sharefolder/
sudo chmod 755 /sharefolder/
sudo /etc/init.d/smbd restart
 ---------------------------------------Public folder above

sudo useradd testuser01
sudo smbpasswd -a testuser01 (specify password)

sudo mkdir /testuser01
sudo chown -R testuser01 /testuser01
sudo chmod 755 /testuser01

sudo nano /etc/samba/smb.conf
#
[testuser01directory]
comment = useronly
path = /testuser01
browsable = yes
guest ok = no
read only = no
create mask = 0755

sudo service smbd restart

--------------------------------User only folder above


Korean input in ubuntu 13.10 linux mint 16

http://klein.tistory.com/515

I used to use ibus input to type in Korean.

With my current version of linux mint right-ALT (hangul) button does not toggle between English and Korean.

Installing nabi resolves this problem.

1. Ubuntu Software Centre - search nabi - install

2. Input Method - choose 'Hangul'

3. Restart xserver