Chitika

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, August 1, 2014

Linux interface Bonding

Bonding is a tool/technique in linux to implement network load balancing or fault tolerance.


Install module

apt-get install ifenslave-2.6


Load module with options

modprobe bonding mode=active-backup miimon=100 updelay=200 downdelay=200

active-backup or 1 mode for fault tolerance
balance-rr or 0 (default) mode for load balance


Enlist interfaces for balancing/fallback

ifenslave bond0 wlan0 eth0


Obtain ip on bond0

dhclient bond0
or
ifconfig bond0 192.168.1.5


Remove bond0 interface

rmmod bonding

Thursday, April 3, 2014

assign IPv6 address

sudo ifconfig eth0 inet6 add 2001:0db8:100:1:2:3:4:5/48

Friday, January 17, 2014

network scan for hosts

NMap utility is used to scan network for different criteria, such as all alive hosts on network can be get using following command:

nmap -sn 192.168.2.0/24

where network is 192.168.2.0/24, and -sn switch tells no ports to consider.

Friday, January 3, 2014

convert offline web to pdf

htmldoc --webpage -f example.pdf example_path/toc.html example_path/*.html
source: http://kmkeen.com/mirror/2009-02-05-14-00-00.html 

wget website subsection fetching

Following "wget" command can be used to fetch portion of website:


wget -r -l3 -k -p -I /docs,/static/images http://www.example.com/man/index.html

Where:
-r   : fetch recursively
-l3 : depth of 3, fist/index page is at depth 1
-k  : convert links to local links for offline viewing
-p  : prerequisites downloads for perfect page viewing (css/images)
-I   : comma seperated list of base path, to only fetch items containing uri starting from these base paths

Wednesday, October 2, 2013

mplayer side by side to anaglyph viewing

mplayer -vf stereo3d,scale sbs.mp4

where, sbs.mp4 is side-by-side stereoscopic movie

linux 3D side-by-side to anaglyph video conversion


mencoder -vf stereo3d,scale sbs.mp4 -o anaglyph.mp4 -oac pcm -ovc x264

where:
sbs.mp4 is input file
anaglyph.mp4 is output file

Monday, September 16, 2013

gnu c/gcc exception handling

man setjmp states:

"setjmp() and longjmp(3) are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. setjmp() saves the stack context/environment in env for later use by longjmp(3). The stack context will be invalidated if the function which called setjmp() returns."

man lngjmp states:

"longjmp() and setjmp(3) are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. longjmp() restores the environment saved by the last call of setjmp(3) with the corresponding env argument. After longjmp() is completed, program execution continues as if the corresponding call of setjmp(3) had just returned the value vallongjmp() cannot cause 0 to be returned. If longjmp() is invoked with a second argument of 0, 1 will be returned instead."

Example at wikipedia:

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
 
enum { SOME_EXCEPTION = 1 } exception;
jmp_buf state;
 
int main(void)
{
  if(!setjmp(state))                      // try
  {
    if(/* something happened */)
    {
      exception = SOME_EXCEPTION;
      longjmp(state, 0);                  // throw SOME_EXCEPTION
    }
  } 
  else switch(exception)
  {             
    case SOME_EXCEPTION:                  // catch SOME_EXCEPTION
      puts("SOME_EXCEPTION caught");
      break;
    default:                              // catch ...
      puts("Some strange exception");
  }
  return EXIT_SUCCESS;
}


#include <stdio.h>
#include <setjmp.h>

#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){
#define CATCH } else {
#define ETRY } }while(0)
#define THROW longjmp(ex_buf__, 1)

int
main(int argc, char** argv)
{
   TRY
   {
      printf("In Try Statement\n");
      THROW;
      printf("I do not appear\n");
   }
   CATCH
   {
      printf("Got Exception!\n");
   }
   ETRY;

   return 0;
}


Advanced Try...Catch...Finally: (source: http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html)

#include <stdio.h>
#include <setjmp.h>

#define TRY do{ jmp_buf ex_buf__; switch( setjmp(ex_buf__) ){ case 0: while(1){
#define CATCH(x) break; case x:
#define FINALLY break; } default:
#define ETRY } }while(0)
#define THROW(x) longjmp(ex_buf__, x)

#define FOO_EXCEPTION (1)
#define BAR_EXCEPTION (2)
#define BAZ_EXCEPTION (3)

int
main(int argc, char** argv)
{
   TRY
   {
      printf("In Try Statement\n");
      THROW( BAR_EXCEPTION );
      printf("I do not appear\n");
   }
   CATCH( FOO_EXCEPTION )
   {
      printf("Got Foo!\n");
   }
   CATCH( BAR_EXCEPTION )
   {
      printf("Got Bar!\n");
   }
   CATCH( BAZ_EXCEPTION )
   {
      printf("Got Baz!\n");
   }
   FINALLY
   {
      printf("...et in arcadia Ego\n");
   }
   ETRY;

   return 0;
}

Wednesday, August 21, 2013

linux: secure, quick and easy sock5 proxy over ssh

Connect to remote server using following ssh command:

> ssh -D 12345 remote-server.com

a sock5 server will started on localhost:12345, port is 12345.

install tsocks package, as sock5 client

> sudo apt-get install tsocks

edit /etc/tsocks.conf

> vi /etc/tsocks.conf

remove everything, and enter following lines:

server = 127.0.0.1
server_type = 5
server_port = 12345

save and quit

Now to run firefox (or any other network application), using sock5, execute following command:

> tsocks firefox

enjoy, secure, quick and easy sock5 proxy over ssh.

Wednesday, February 13, 2013

linux enable sftp

To enable sftp on linux (having openssh-server installed), one have to uncomment/open following line in /etc/ssh/sshd_config file, and restart sshd server (this line is already enabled in all the distributions by default, means sftp is already working):

Subsystem       sftp    /usr/lib/ssh/sftp-server


To connect to linux sftp, use sftp user@server from command line and use normal ftp (put/get/mput/mget) commands to retrieve and send files to server.