Rayhan’s blog (raynux.com)

Rayhan’s Personal Web Blog Site

Entries Comments

IPTABLES quick command list

15 April, 2009 (12:09) | Fedora, Linux, Reference, Ubuntu | 3 comments

Tags: , , , ,

Iptables is the default and powerful firewall that works on almost all Linux version including Ubuntu and Fedora. Here I have listed some important commands and a short description of each command for quick help. It can help people who already know little Iptables.

manage chain:
# iptables -N new_chain				// create a chain
# iptables -E new_chain old_chain  		// edit a chain
# iptables -X old_chain				// delete a chain

redirecting packet to a user chain:
# iptables -A INPUT -p icmp -j new_chain

listing rules:
# iptables -L					// list all rules of all tables
# iptables -L -v				// display rules and their counters
# iptables -L -t nat				// display rules for a specific tables
# iptables -L -n --line-numbers			// listing rules with line number for all tables
# iptables -L INPUT -n --line-numbers		// listing rules with line number for specific table

manage rules:
# iptables -A chain				// append rules to the bottom of the chain
# iptables -I chain [rulenum]			// insert in chain as rulenum (default at the top or 1)
# iptables -R chain rulenum			// replace rules with rules specified for the rulnum
# iptables -D chain	rulenum			// delete rules matching rulenum (default 1)
# iptables -D chain				// delete matching rules

change default policy:
# iptables -P chain target			// change policy on chain to target
# iptables -P INPUT DROP			// change INPUT table policy to DROP
# iptables -P OUTPUT DROP			// change OUTPUT chain policy to DROP
# iptables -P FORWARD DROP			// change FORWARD chain policy to DROP

Tour to Jaflong: where nature and beauty meet together

11 April, 2009 (15:52) | Bangladesh, personal, Travel | 4 comments

Tags: , , , , , , ,

Jaflong is one of the beautiful tourist place in Bangladesh. I visited the place 2 more times, so the place wasn’t new to me. Though, I have managed one of my friends to visit the place again. I borrowed a nice binocular from hasin bhai for that purpose. It was a nice addition to our journey.


Tour Photos in Flickr: http://www.flickr.com/photos/raynux/tags/jaflong2009/
I have taken all the pictures using my Motorola V3i Mobile.

Update your social networking status from command line

28 February, 2009 (13:27) | Linux, programming, Python, web, Web Services | 10 comments

Tags: , , ,

This is my first python script, Throughout the learning process I want to make something use full and I know that the best way to learn a new programming language is to start with some real project.

Updating your social networking status is now a frequent job. To make this job easier there are lots of web services, desktop applications, mobile applications, plug-ins available to the users. Some people wants to update there status from a single place. Like others Ping.fm, Hellotxt.com are providing single place service with a variety of options. But I think that updating status from command line is the easiest way for most of the Linux users who loves their terminal.

I have used ping.fm REST API for my script as a result It can update all the services registered with ping.fm at once or a single service putting additional parameter. You just need the Internet connection and terminal to put the command.

File: ~/bin/raypm

#! /usr/bin/env python
A Simple program to update your social networking status using ping.fm

This program will update all your social networking sites via ping.fm.

	- sign for a account at ping.fm
	- setup ping.fm for desired social networking sites.
	- get your developer api key http://www.ping.fm/developers
	- get your user key from http://www.ping.fm/key

	- shell > raypm "your message text to update your all social networking status, like twitter, facebook, linkedin"
	- shell > raypm twitter "your message text to update twitter status only"
	- shell > raypm facebook "your message text to update facebook status only"

@author		: Md. Rayhan Chowdhury
@email		: ray@raynux.com
@website	: www.raynux.com
@license	: GPL
@copy		: All right are reserved

import urllib
import urllib2
import sys
from xml.etree import ElementTree as ET

# modify __apiKey__ with your own
# get your apiKey from http://www.ping.fm/developers

# modify __userKey__ with your own user key
# get your user key from http://www.ping.fm/key

__apiUrl__ = 'http://api.ping.fm/v1/'

# debug
# 1 - will not update your status, dump xml response text
# 0 - will update your status
debug = 0

class RayStatus:

	def __init__(self, msg = None, service = None):
		"create message"    

		global debug
		data = {	'api_key'		: __apiKey__,
					'user_app_key'	: __UserKey__,
					'post_method'	: 'default',
					'body'			: msg,
					'debug'			: debug 
		if service is not None:
			data['service'] = service		
		#Encode the data to be posted 
		data = urllib.urlencode(data)	

		print "Loading..."
		# post the data
		req = urllib2.Request(__apiUrl__ + 'user.post', data)		
			response = urllib2.urlopen(req)

			responseXML = response.read()
			# parse response data
			result = ET.XML(responseXML)
			if result.attrib is not None:
				if result.attrib['status'] == 'OK':
					print 'Congratulations! your message posted successfully!';
					print 'Error: ' + result[2].text
			if debug:	
				print "debug info: "
				print responseXML
		except urllib2.URLError, e:
			if hasattr(e, 'reason'):
				print 'Could not connect to the server.'
				print 'Reason: ', e.reason
			elif hasattr(e, 'code'):
				print 'The server couldn\'t fulfill the request.'
				print 'Error code: ', e.code

if __name__ == '__main__':
		if (len(sys.argv) == 2):
			RayStatus(sys.argv[1], None)
		elif (len(sys.argv) == 3):
			RayStatus(sys.argv[2], sys.argv[1])
	except IndexError:
		print "Please enter your desired message to be posted."

To make the script working, you need to sign up for a ping.fm user account, and registrar for services you want, they support all major social networking sites including twitter, facebook, linkedIn.

You will need to get these two keys.
- developer api_keys from http://ping.fm/developers/
- user app key from http://ping.fm/key/

I have my developer api key from ping.fm which will work for you, but I can’t disclose it openly. It will be great to have your own api key and user key is unique for each user.


  1. create a directory inside your home folder named bin
  2. create a file named raymp inside the bin folder and copy and paste the code
  3. replace api key and user key with your own.
  4. make the file executable with this command
    # chmod +x ~/bin/raypm
  5. you may need to restart the system to add the newly added bin folder to PATH.

& done.

now you can update your status with the following commands
# raypm "update all social networking status at once"
# raypm twitter "update twitter status only"
# raypm facebook "update facebook status only"

7 things about me

22 February, 2009 (15:47) | personal | 4 comments


Yesterday hasin bhai has tagged me to write 7 things about me. Though I don’t like to write about myself, my 7 things are given bellow…

1. I am a very lazy parson.
2. I can pass the whole day watching movies on TV.
3. I almost forgot C, C++, VB, FORTRAN, Corel Draw, Flash because of lack of practice
4. I passed my S.S.C. from humanities group.
5. While doing my graduation in civil engineering, I taught Accounting, Commerce, Economics to one of my student for O-Level Exam
6. I never dare to play Football because of direct foul habit in our country
7. I normally  avoid social events, parties, etc so little unsocial

here are 7 people I would like to read seven things about them

1. anupom syam
2. ahsanul bari
3. shoeb abdulla
4. rubel
5. arafat rahman
6. mahmud ahsan/
7. Asif Anwar

And here goes the rules:

- Link your original tagger(s), and list these rules on your blog.
- Share seven facts about yourself in the post – some random, some weird.
- Tag seven people at the end of your post by leaving their names and the links to their blogs.
- Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

Mac on my ubuntu laptop

19 February, 2009 (16:06) | Linux, personal, Ubuntu | 2 comments

Tags: , , , , ,

Mac4Lin is a great project which brings mac user interface to linux desktop. Yesterday I installed Mac4Lin on my laptop running ubuntu intrepid idex. Installation needs some advance configuration which is not suitable for newbie right now even I couldn’t install screenlets desktop widget. But still it’s cool and I am really impressed with the new mac like interface on my laptop. I have added couple of screenshots on my flickr photo-stream.


More Photos: http://www.flickr.com/photos/raynux/tags/mac4lin/

Translatation Services Available On The Net

17 February, 2009 (17:11) | Ajax | 2 comments

Tags: , , ,

There are lots of services available on the net. Some of them are really helpful. My intention of this post is to introduce you with some necessary services available on the net and this is the first post of this category.

There are some translation services available on the net like Google Translate, nicetranslator.

For normal user I have found that nicetranslator is more intuitive and easy tool, specially for those who are studying or have interest on foreign languages. The User Interface of nicetranslator is pretty simple yet powerful…Their ajax implementation is really cool. You can have a look at them.

Google Translate is a good option for advance users and programmers as they have public API. It also provide support for more languages than nicetranslator and have some other options. And It seems that nicetranslator is using the Google Translate API. If you are a programmer you can also use Google Translate for your own project. I have made a PHP Class for Google Translate API for one of my project, and hoping to release it as open source on the net when it’s final.

Install Additional softwares by a single command on Ubuntu

21 November, 2008 (02:49) | Linux, MySQL, personal, PHP, Reference, Ubuntu | 9 comments

Tags: , , , ,

I have created a bash script file to install almost all necessary softwares to run and work on a Ubuntu box. I have tried this script in Ubuntu 8.04 Hardy Heron and Ubuntu 8.10 Intrepid Ibex. Softwares I have placed in this script covers PHP-MySQL development and desktop applications for graphics, multimedia, to Internet applications. You can also add your favourite softwares in the script.

File: RayInstall.sh

# RayInstall.sh
# Ubuntu Intrepid & Hardy
# A very simple Bash Script file to automate installation of necessary
# softwares for PHP-MySQL development and desktop uses in a ubuntu box
# This may take several hours or even days depending on your internet connection speed.
#	It tooks 8 Hours for me with about 70-130 KBps of speed
# @uses Aplication -> Accesories -> Terminal
#		Now write following command "sudo sh ./RayInstall.sh" without quotes
#		and press enter button on your keyboard
# @author ray@raynuxcom
# @licence GPL

# For PHP-MySQL Based Development

# Install Apache version 2 web server
apt-get -y install apache2 apache2-doc

# Install PHP with necessary modules
apt-get -y install php5 libapache2-mod-php5 php5-cli
apt-get -y install php5-curl php5-dev php5-gd php5-gmp php5-imap php5-ldap php5-mcrypt php5-mhash php5-ming php5-odbc php5-pspell php5-snmp php5-sybase php5-tidy curl libwww-perl imagemagick

# Install MySQL Database server
apt-get -y install mysql-server php5-mysql mysql-gui-tools-common

#Restart apache
/etc/init.d/apache2 restart

# Install Webmin, A web based frontend for linux box.
apt-get -y install webmin

# Install Subversion & Rapidsvn a subversion gui client tools
apt-get -y install subversion subversion-tools libapache2-svn
apt-get -y install rapidsvn

#Restart apache
/etc/init.d/apache2 restart

#Install Doxygen, An documentation tools for PHP Application
apt-get -y install doxygen doxygen-gui doxygen-doc graphviz

# Install Phpmyadmin, A web based mysql administration tools
apt-get -y install phpmyadmin

# Install Java runtime for Eclipse PDT to work properly
apt-get -y install sun-java6-bin sun-java6-jdk sun-java6-jre

# Install Eclipse PDT
# Just download the pdt-all-in-one peckage from zend site
# http://downloads.zend.com/pdt/all-in-one/pdt-1.0.3.R20080603_debugger-5.2.14.v20080602-all-in-one-linux-gtk.tar.gz
# Unpack it in a suitable location.
# run eclipse/eclipse from the unpacked folder and you are done
# Now install Subclipse plugin using eclipse update tools

# Graphics, 2D and 3D Modeling Softwares & tools

# Install inkscape, An Illustrator alternative
apt-get -y install inkscape

# Install dia and graphical UML modeling tools
apt-get -y install dia

# Install Scribus, An alternative to Adobe Pagemaker
apt-get -y install scribus

# Install Cheese,  Webcam Software, a video and photo shoot application with cool effects for the GNOME desktop
apt-get -y install webcam cheese

# Install QCAD, and linux alternative to CAD Program.
apt-get -y install qcad

# Install Blender, Linux alternative for 3D Modeling
apt-get -y install blender

# Misc. Tools

# Install Wine, to run windows program
apt-get -y install wine

# Install XChm to read CHM Help file and Manual
apt-get -y install xchm

# Multimedia Players and codec

# Install GStreamer restricted codec to run mp3 and other media file
apt-get -y install gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad

# XMMS2 Media player
apt-get -y install xmms2 gxmms2

# Install vlc player, An alternative media player. Can play DVD file with title
apt-get -y install vlc vlc-plugin-*

# Install Amarok music player
apt-get -y install amarok

# Install k3b, A dvd burner application
apt-get -y install k3b

# Network and internet tools

# Install OpenSSH server to access your ubuntu box remotely
apt-get -y install openssh-server openssh-client

#Install gnome-network-admin, not available in default ubuntu 8.10
apt-get -y install gnome-network-admin

# Install Webhttrack, Website copier tools for linux
apt-get -y install webhttrack

# Install kopete instant messenger
apt-get -y install kopete

# install Internet Explorer in Ubuntu (Experimental)
apt-get -y install wine cabextract msttcorefonts

#run the following command manually to install IE
# wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
# tar zxvf ies4linux-latest.tar.gz
# cd ies4linux-*
# ./ies4linux

If you are using Ubuntu on your computer and want to automate the installation process utilising this script then perform the following steps:

  • Create a file name RayInstall.sh in you home folder.
  • Copy and paste the above code inside the the file and save it.
  • Open a terminal window from Applications -> Accessories -> Terminal
  • Write the following command
  • sudo sh ./RayInstall.sh
  • press Enter
  • Now it will start installing all the softwares listed in the script and you may need to provide some information during installation process when needed.

This script may be helpful for newbies. If you have any comment or suggestion regarding this script please let me know as I am also a newbie in Ubuntu.

Store and Display image from MySQL database

20 November, 2008 (16:09) | MySQL, PHP, programming, Reference | 81 comments

Tags: , , , ,

A basic approach to upload and save image to a MySQL database and then display the image from the database.

First you need to create a table in MySQL Database to store the image data. Log into you database and run the following sql command:
CREATE TABLE  `images` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`size` int(11) default NULL,
`type` varchar(20) default NULL,
`content` mediumblob,

Once the table have been created, we are ready to write codes. Now create a folder in you webserver named rayImg and create image.php and upload.php files inside the folder.

Open the image.php, copy and paste the following code and save it.

File: image.php

	 * Display image form database
	 * Retrive an image from mysql database if image id is provided.
	 * @example to display a image with image id 1, place <img src="image.php?id=1" > in your html file.
	 * @author Md. Rayhan Chowdhury
	 * @copyright www.raynux.com
	 * @license LGPL

	// verify request id.
	if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
		echo 'A valid image file id is required to display the image file.';

	$imageId = $_GET['id'];

	//connect to mysql database
	if ($conn = mysqli_connect('localhost', 'root', 'root', 'test')) {
		$content = mysqli_real_escape_string($conn, $content);
		$sql = "SELECT type, content FROM images where id = {$imageId}";

		if ($rs = mysqli_query($conn, $sql)) {
			$imageData = mysqli_fetch_array($rs, MYSQLI_ASSOC);
		} else {
			echo "Error: Could not get data from mysql database. Please try again.";
		//close mysqli connection

	} else {
		echo "Error: Could not connect to mysql database. Please try again.";

	if (!empty($imageData)) {
		// show the image.
		header("Content-type: {$imageData['type']}");
		echo $imageData['content'];

Now open the update.php, copy and paste the following code and save it.

File: upload.php

 * Upload an image to mysql database.
 * @author Md. Rayhan Chowdhury
 * @copyright www.raynux.com
 * @license LGPL

// Check for post data.
if ($_POST && !empty($_FILES)) {
	$formOk = true;

	//Assign Variables
	$path = $_FILES['image']['tmp_name'];
	$name = $_FILES['image']['name'];
	$size = $_FILES['image']['size'];
	$type = $_FILES['image']['type'];

	if ($_FILES['image']['error'] || !is_uploaded_file($path)) {
		$formOk = false;
		echo "Error: Error in uploading file. Please try again.";

	//check file extension
	if ($formOk && !in_array($type, array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif'))) {
		$formOk = false;
		echo "Error: Unsupported file extension. Supported extensions are JPG / PNG.";
	// check for file size.
	if ($formOk && filesize($path) > 500000) {
		$formOk = false;
		echo "Error: File size must be less than 500 KB.";

	if ($formOk) {
		// read file contents
		$content = file_get_contents($path);

		//connect to mysql database
		if ($conn = mysqli_connect('localhost', 'root', 'root', 'test')) {
			$content = mysqli_real_escape_string($conn, $content);
			$sql = "insert into images (name, size, type, content) values ('{$name}', '{$size}', '{$type}', '{$content}')";

			if (mysqli_query($conn, $sql)) {
				$uploadOk = true;
				$imageId = mysqli_insert_id($conn);
			} else {
				echo "Error: Could not save the data to mysql database. Please try again.";

		} else {
			echo "Error: Could not connect to mysql database. Please try again.";

		<title>Upload image to mysql database.</title>
		<style type="text/css">
				margin: .2em;
				border: 1px solid #555;
				padding: .2em;
				vertical-align: top;
		<?php if (!empty($uploadOk)): ?>
		  		<h3>Image Uploaded:</h3>
				<img src="image.php?id=<?=$imageId ?>" width="150px">
				<strong>Embed</strong>: <input size="25" value='<img src="image.php?id=<?=$imageId ?>">'>

		<? endif; ?>

		<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data" >
		  	<h3>Image Upload:</h3>
		  	<input type="hidden" name="MAX_FILE_SIZE" value="500000">
			<input type="file" name="image" />
		    <input name="submit" type="submit" value="Upload">

Replace line

mysqli_connect(‘localhost’, ‘root’, ‘root’, ‘test’)


mysqli_connect(‘your host’, ‘your username’, ‘your password’, ‘your database name’)

in both the file and save again.

You are done. Open upload.php from your browser and upload you desired image and view the uploaded image.

Last evening at Fantasy Kingdom

16 November, 2008 (08:07) | personal, Travel | 2 comments

Jubel, my best friend at Sylhet came to Dhaka for a 2 days trip. To give him some excitements we went to Fantasy Kingdom last day. We reached there at about 5 PM. We rode on some exciting rides like roller coaster, flying bird etc. It was an exciting and enjoyable evening for both of us.

Here are some photos of the tour taken by my Motorola V3i mobile phone.





View all pictures: http://www.flickr.com/photos/raynux/tags/fk15nov/

Recovering Ubuntu or Fedora Linux after installing windows

21 September, 2008 (01:40) | Fedora, Linux, Reference, Ubuntu | 4 comments

Tags: , , , , , ,

Running linux with windows in dual boot mode is not hassle free at all. Specially if you reinstall or repair windows, your linux system will disappear. As a newbie you may stop using linux or reinstall it again instead of solving the problem. In this article I will share my experience on how to recover the boot option for linux. I will cover two well known linux distro ubuntu 8 and fedora 7. I will try to cover the fail safe situation here.

In both Fedora and Ubuntu this task includes two basic steps. These are:

  • Enter into your existing hard disk linux system.
  • Setup GRUB Boot Loader using GRUB program.

a. Enter into your existing hard disk linux system.

Fedora 7:

In fedora recovering grub is easy task as fedora automatically mount the existing system image to /mnt/sysimage in rescue mode.

  1. Insert the fedora installation cd to boot from cd.
  2. When the boot menu appear enter the rescue mode. A message will be prompt saying mounting the existing fedora system on /mnt/sysimage, click ok.
  3. In rescue mode you will be in a shell
  4. Enter the following command
    #chroot /mnt/sysimage
  5. Now you are in your existing fedora operating system.

Ubuntu 8.04 LTS:

In ubuntu you will have to mount the existing system image manually.

  1. Insert the ubuntu live cd and start a live session from cd.
  2. open the terminal window
  3. the following command will display currently mounted device or harddisk partitions
    #df -h
  4. get the device name for /boot if exists or / (root) partition say /dev/sda9.
  5. enter the following command
    #sudo mkdir ubuntu
    #sudo mount -t ext3 /dev/sda9 ubuntu
  6. If you have separate /usr partition say /dev/sda7 enter the following command too.
    #sudo mount -t ext3 /dev/sda7 ubuntu/usr
  7. Enter the following command to mount /proc and /dev and change chroot.
    #sudo mount -t proc none ubuntu/proc
    #sudo mount -o bind /dev/ ubuntu/dev
    #sudo chroot ubuntu /bin/bash
  8. Now you are in your existing ubuntu operating system.

b. Setup GRUB Boot Loader using GRUB program.

In grub you are mainly required to find the boot device and set the root to bood device.

  1. Insert the ubuntu live cd and start a live session from cd.
  2. Find the existing boot device using following command. Which will out put something like (hd0,0) or (hd0,5) say (hdX,Y).
    #grub> find /boot/grub/stage1
  3. Use the above output in the following two commands.
    #grub> root (hdX,Y)
    #grub> setup (hdX)
    #grub> quit
  4. if everything is ok then you are done. just reboot the system.

This article is completely based on my current experience and I am still a newbie in linux environment. so there may have sevaral other options to do the same task.

« Older entries

 Newer entries »