Karthik selvakumar's log

All my Garbage talks and junk codes

Building your fax machine with nothing :)

Now you can build your own fax machine with your linux box

Requitements :

i) Linux OS

ii) GSM mobile

iii) A basic printer device

Softwares:

i) Gnokii-smsd

ii) Mysql

if you have any problem in configuring your mobile and your linux you can refer to this article

Now assume your sms daemon is up and running and you have all your messages in INBOX table of SMSGW database

with simple steps you can make your own fax machine

step 1)

configure your printer and check wheteher a test page is being printed . Else install appropriate driver first from hplip

step 2)

then as in dicitionary server connect to mysql database  and  just add an if  condition

the core part is

if(word.startswith(“fax:”)):
up=” echo \””+str(word.replace(“fax:”,””))+”\” > print.txt”;
low=” cat print.txt | lpr -P HP_LaserJet_1020″

then just execute the both as

import os

os.system(up)

os.system(low)


step 3)

Here , after lpr -P < your printer name > for me it is HP_LaserJet_1020

then  mention the mobile number as the fax number of your company  and you will start receiving faxes in papers instead of text messages 🙂

step 4)

Then let the mobile you attached to PC be +xxxxxx

now people who fax you will send a message like

fax:< Their message here >

step 5)

you can add an authentication  module in between receiving and printing the message

Enjoy 🙂

Advertisements

முத்துகுமரன்க்கு ஒரு கவிதை :)

கை நீட்டி மேடையில் பேசியவன் – உன்னால்
கை கட்டி பின் வரும் மாயம் என்ன

கைபேசி கையாள தடவியவன் அன்று – அது
கையுக்குள் புகையும் வரை  வருப்பவனாய்    இன்று

படம் பார்க்க திரை சென்றோம்
நான் பார்த்தது திரைப்படம்  ஆனால்
நீ பார்த்ததோ அவள் புகைப்படம்  தானே

சர்பத்தினை பெயராய் கொண்டு
சிற்பமாய் இருந்தவள் அவள்

சிந்தனை பல செய்து வைத்தாய் – எல்லாம்
சிதறிப்போனதே I.V.   இலே

திவ்யம் ஒரு கணம் மறைய
தேவி மறு கணம் புனைந்தால்
‘உன்னை  அறியா என்று’ – அன்றோ

சோதனையிலும் சுந்தரனாய் சிரித்தாய் – ஆனால்
உன் மனம் பட்ட வேதனை தான் எத்தனை எத்தனை !!!

lock and unlock gnome with gsm

tested with :

i) ubuntu 8.10

ii)gnokii

iii) mysql 5

iv) lg kp 199

functionalities :

i) just message “lock” to your server mobile to lock the screen

ii)   “unlock” to release the screen

iii) you can even change the pidgin status by messaging “status:your status here

iv )  execute any shell commands that take return value  below 160  characters

procedure:

step 1)

set the memory for sms to sim and run the smsd daemon as

sudoo /usr/sbin/smsd -u root -d smsgw -c localhost -m mysql -u root –password=password -b SM -f /var/log/smsdaemon.log

step 2)

run this python script  and minimize the shell

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

processed=1;
# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”123456″

db=”smsgw”

# Optionally get input from user

#    print ” Enter Host :”

#    host=raw_input()

#    print ” Enter Password :”

#    passwd=raw_input()

#    print ” Enter database :”

#    db=raw_input()

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\””)

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id,processed from inbox where id=(select max(id) from inbox)”)

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later 😉

number=result[0]

row=result[2]

processed=result[3]

if(processed==0):

# script to get meaning of a word from google server
if(word==”lock”):
up=”gnome-screensaver-command –lock”;
elif(word==”unlock”):
up=”xset dpms force on && gnome-screensaver-command -d”;

elif(word.startswith(“status:”)):
up=” purple-remote \”setstatus?status=available&message=”+str(word.replace(“status:”,””))+”\””;

else:
up=word+” >meaning.txt”;

print up;

#set the entity to be processed when taken out

cursor.execute(” update inbox  set processed=1 where id=”+str(row));

# run the command in shell and write it to file named meaning.txt

os.system(up)

# open the file in read only mode

filehandle=open(‘meaning.txt’,’r’)

# load the meaning in the string text

text=filehandle.read()

print ” text is “+text;

# we no more need this

filehandle.close()

if(text!=””):
cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections 🙂

cursor.close()

db.close()

#thank you !

step 3)

your done with now message to the mobile you have connected like lock or unlock or status:status to see the magic happen 🙂

A simple start to SVN

SVN is a version control system used to track your various versions of your software over various levels called Revisions.

Basically every software will be stored in SVN as REPO called Repositories .

Step1 :

First before starting with your coding create a repo name in SVN as :

svnadmin create<your-repo-name>

e.g) svnadmin create mediaplayer

now you have created a repo named mediaplayer

this copy is the master copy for all clients

this will be a directory with some system defined files in it

note the directory you have  created a repositiory

Step 2:

now you cannot directly do modify on master copy

you have to checkout this repo to some workspace and start working

let it be a directory called workspace

mkdir workspace

cd workspace

now you can checkout the master copy and start your coding process

svn co file:///home/<user-name>/<repo-name>

eg:)  svn co file:///home/karthik/mediaplayer

now you will have a directory named mediaplayer

go into the directory  by

cd mediaplayer

then start a code name it as myfile.java

now save it in this directory  . To add this into your master copy do

svn add  <file-name>

eg) svn add myfile.java

Step 3:

you can optionally use these commands

i) svn commit – to  commit the current modification to the master copy ( Do this whenever you do minor changes to you files)

ii) svn status – to check the status of files in working copy

here ? means unknown  A means added M means modified but not added

iii) svn update – to update to the latest revision of the master copy ( this will be usefull when more than one client has modified the master copy without your knowledge )

for more details refere here

Thank you 🙂

Running SMS Dictionary server in your Home

Do you want to run a dictionary server that messages you the actual meaning

Requirments :

i)  A GSM mobile phone

ii)  Linux  with python

iii) Mysql Database

iv)  Gnokii-SMSD

You must be sure that gnokii-smsd is up and running and database is available

if not refer to my previous post here

Code :

This code simply connects to dictionary.org and gets the meaning for the word that is latest in INBOX table and writes the meaning to OUTBOX table which will be sent to user later .May have bugs in it please report me at earliest 🙂

copy and paste the code to a file . let it be dict_server.py . code is below :

#!/usr/bin/python

#    before running this program you must configured gnokii-smsd and it must be up and running
#     @Author:    Karthik selvakumar
#    Name :     Dictionary Server

# install python-MySQLdb  before importing this module

import MySQLdb

# imported inorder to perform shell operations

import os

# run as a daemon and never exit this thread

while(True):

#defines the database parameter change according to your configuration

host=”localhost”

user=”root”

passwd=”password”

db=”smsgw”

#creates a database object for corresponding config

db=MySQLdb.connect(host,user,passwd,db)

cursor=db.cursor()

#performs pruning of inbox table which may contain null entities

cursor.execute(“delete from inbox where text=\”\””)

#gets the latest entered SMS from Mysql server

cursor.execute(” select number,text,id from inbox where id=(select max(id) from inbox)”);

record=cursor.fetchall()

for result in record:

# gets the word to find meaning

word=result[1]

# get the number bcoz u have to reply the meaning to this number later 😉

number=result[0]

row=result[2]

# script to get meaning of a word from google server

up=’/usr/bin/curl -s -A \’Mozilla/4.0\’ \’http://www.google.com/search?q=define%3A\”

low=’| html2text -ascii -nobs -style compact -width 500 | grep “*” | head -n 1 -q | tail -n 1 > meaning.txt’

# run the command in shell and write it to file named meaning.txt

os.system(up+word+low)

# open the file in read only mode

filehandle=open(‘meaning.txt’,’r’)

# load the meaning in the string text

text=filehandle.read()

# we no more need this

filehandle.close()

# insert into outbox table which will send the meaning of the word to the phone number later

cursor.execute(“insert into outbox(number,text) values(%s,%s)”,(number,text))

# close all active connections 🙂

cursor.close()

db.close()

#thank you !

now run the dictionary daemon by running python dict_server.py in terminal

whenever a message is received to your mobile it will be read by dict_server.py and meaning of that word will be in outbox table

to see run select * from outbox ; in mysql console

Enjoy 🙂

Installing Network Simulator 2 in Ubuntu

Are you baffled by random errands saying ”  ns2 doesn’t work on ubuntu ” and so ?

Are you a linux geek don’t wanna boot to windows for network simulator software ?

did your lab admin made a mess with your system in the name of installing ns2 😀 ?

then you are in a right place 🙂

You can make NS working in your system by putting little effort  on your ubuntu 🙂

Step 1:

Download network simulator software from here

if you prefer other old versions you can swich by viewing files in that page

the file will be of almost 57 MB

Step 2:

Extract the files to your own desired directory

I did in /home/karthik/Desktop/

step 3:

now go to your working directory of ns2 by

cd /home/karthik/Desktop/ns-allinone-2.34

step 4:

Run this command to check any unresolved dependencies existing between installation

sudo apt-get install build-essential autoconf automake libxmu-dev

run the command ./install in terminal

it will take around 5 minutes

step 5:

Well Thats were your installation of ns2 exits 🙂

now you have to configure to make it alive

you have to edit in the shell

run gedit ~./bashrc

add at end of the file this lines

remember change  /home/karthik/Desktop/ to your file path say /home/host-name/


# LD_LIBRARY_PATH
OTCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/karthik/Desktop/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_
LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/karthik/Desktop/ns-allinone-2.34/bin: /home/karthik/Desktop/
ns-allinone-2.34/tcl8.4.18/unix : /home/karthik/Desktop/ns-allinone-2.34/tk8.4.18/unix
NS=/home/karthik/Desktop/ns-allinone-2.34/ns-2.34/
NAM=/home/karthik/Desktop/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

now save the file and close it

run source ~/.bashrc

ignore if any errors 😉

then run ./validate

this is the longest step it takes 30-45 minutes hence you can have a meal during the course of time 😉

step 6:

this  is editing thing ( optional )

just make  links to the files in /home/karthik/Desktop/ns-allinone-2.34/bin by right click on all files and choose make link

copy  all and paste to /usr/bin/ directory  by running

sudo nautilus

then rename the file name for eg) link to ns to ns and so on . do this till all files are renamed .

step 7:

Sample code

now u can check out a demo to test you ns 2 by writing a sample code as below :

#Create a simulator object
set ns [new Simulator]

#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a ‘finish’ procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}

#Create two nodes
set n0 [$ns node]
set n1 [$ns node]

#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 “finish”

#Run the simulation
$ns run

now copy this code and paste to a file say  myfirstprogram.tcl

then run ns myfirstprogram.tcl

you must see a window like this :

my ubuntu screen running NS2

and  …   You did it , Enjoy   🙂

Cursor Play With your neigbour System

If you have more than one system and need to acces all with a single mouse ?

Wanna hack your neigbour node and drive him mad?


you can use this code to move the cursor

and with little modification you can emulate a whole mouse and keyboard functionalities too …

Download My code from here


To Do :


step i) run the server.class first in machine u want to control say A

java server <port_numbr 1000-65535>


step ii) run the client.class in second machine u have the mouse say B

java client <ip of machine say 10.2.3.1 > <port_number_server 1000-65535>


step iii) move  mouse in machine B so that it moves on machine A

Algorithm behind :

i)  get the mouse position from master machine

ii) send the position in a ‘encrypt‘ string with X and Y positions merged

as encrypt=X*10000+Y ( I use 10000  here assuming your screen resolution is not more than 10000X10000 😀 )

iii) send the string to slave node using Socket output stream

iv) get the encrypt string and extract x and Y position  by

X=encrypt/10000;

y=encrypt – X;


v) Now move the position of slave machine by mousemove(X,Y) method

vi) You can add leftclick , right click and keyboard keys too as above  🙂

Keyboard as Network Packet Monitor

You can transform Your NUM lock and SCROLL lock led’s to monitor packets send and receive 🙂

Follow the simple steps below :

i) Installation:

Install tleds package  bye sudo apt-get install tleds

ii) Configure :

now configure the interface you use

say for ethernet  run tleds eth0

and for wirless  run tleds wlan0

Perform a restart 🙂

iii) Customize :

Now you can adjust the delay to very quick response to low response rate by adjusting -d paramter in tleds

for very quick run tleds  eth0 -d 1

for low speed run tleds eth0 -d 200

now you have  tranformed your keyboard to packet monitoring system as below :


enjoy 🙂

Facebook mouseclicks hack !

I came across a facebook application which counts maximum number of clicks per second and thought of emulating it in java 😉

it is as simple as a crap code … with simple steps Download it from here

step 1:

I wrote a java code which automtes mouseclicks for N times by for loop

the code seems like :

import java.awt.Robot;
import java.awt.event.InputEvent;
/**
*
* @author karthik
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Throwable {
Robot r=new Robot();

System.out.println(“Hurry up ! you have 10 seconds left “);
System.out.println(“This time you must have focused your mouse pointer on START button of facebook appln”);
r.delay(10000);

// TODO code application logic here
for(int i=0;i<10000;i++){
r.mousePress(InputEvent.BUTTON1_MASK);
System.out.println(“Clicking “+i+”th time “);
r.mouseRelease(InputEvent.BUTTON1_MASK);
System.out.println();
System.out.println();
}System.out.println(“Congrats ! you did it man  B-)”);

}
}

now save the code as Main.java in a directory c:\ in windows or /home in linux

step 2:

open terminal

compile the java code by running from the location where code is located by

javac Main.java

in the mean time open the facebook application

step 3:

Run the java code now this is critical part

java Main

( you can directly run this  by extracting Main.java.zip from above )

you will get a screen saying

“Hurry up ! you have 10 seconds left

This time you must have focused your mouse pointer on START button of facebook appln”

now focus your mouse pointer to the START button of fb appln

you will get a count more than 200 sometimes even 300 clicks per second ( depending on ur jvm )

for more clear details watch the video below :

Thank you 🙂

Disclaimer :

If you move your mouse button other than start button you will get random results around screen and may hang at times so keep the mouse pointer in START button for atleast a minute 😉

Music in Humble terminal

i)  Are you in need of humble player which consumes least your memory

ii)  If your xserver doesnt open and your prompted to a black terminal   and need of a playing music..

iii) if your admin blocked gui

Dont worry still you can hear your favourite  Music files by following simple steps

Step 1:

install the sox for linux by running

sudo apt-get install sox

Step 2:

install mp3 codec for sox (since most of our songs are in .mp3 )

sudo apt-get install libsox-fmt-mp3

Step 3 :

Now your done with  🙂

just locate the music folder and run the file

karthik@karthik: play  my-favourite-song.mp3

for eg:

karthik@Karthik:~/Music$ play I\’m\ So\ Available.mp3

I’m So Available.mp3:

File Size: 7.93M     Bit Rate: 239k
Encoding: MPEG audio    Info: 2009
Channels: 2 @ 16-bit   Track: 3
Samplerate: 44100Hz      Album: Akon – Collection
Replaygain: off         Artist: Akon Feat. Flo-Rida
Duration: 00:04:25.51  Title: I’m So Available

In:0.84% 00:00:02.23 [00:04:23.28] Out:107k  [  ====|====- ]        Clip:0

this is what you will see

Step 4:

not only listening you can also record from terminal

karthik@karthik: rec my-recording.wav

you will se output recording screen as

Input File     : ‘default’ (alsa)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

In:0.00% 00:00:01.96 [00:00:00.00] Out:90.1k [      |      ]        Clip:0

now your recording will be saved in my-recording.wav file in music folder

enjoy with sox 🙂