24 August 2019

Disclaimer

Disclaimer

Disclaimer

The author will not take any liability for any damage(s) caused by use, misuse, improper use etc. of the tutorial(s) by the author. If any damage(s) has occured, the author can't be held responsible for it. The reader are responsible on their own when following (and using) the tutorial(s).

All tutorials are for educational purposes.


Author: Jor Teron <jor dot teron at gmail dot com> Goto bottom

Input:

21 July 2015

Data Security: Cryptsetup

Data Security: Cryptsetup

Data Security: Cryptsetup

Cryptsetup

according to the MAN page:
cryptsetup - manage plain dm-crypt and LUKS encrypted volumes

..cryptsetup is used to conveniently setup dm-crypt managed device-mapper mappings. These include plain dm-crypt volumes and LUKS volumes. The difference is that LUKS uses a metadata header and can hence offer more features than plain dm-crypt...




• Installing Cryptsetup:
sudo apt install cryptsetup


***SETUP***

• Creating a container:
dd if=/dev/urandom of=~/my_encrypted_drive.dd bs=1M count=256

• Format it:
sudo cryptsetup luksFormat ~/my_encrypted_drive.dd

• Opening it:
sudo cryptsetup luksOpen ~/my_encrypted_drive.dd my_drive
my_drive will appear in /dev/mapper/.

• Create a filesystem within it:
mkfs -t ext4 /dev/mapper/my_drive

• Mount the container:
sudo mount -t ext4 /dev/mapper/my_drive ~/mnt/


***Consequence run***

sudo cryptsetup luksOpen ~/my_encrypted_drive.dd my_drive
sudo mount -t ext4 /dev/mapper/my_drive~/mnt/


• Unmounting:
sudo umount ~/mnt/
sudo cryptsetup luksClose my_drive


• Changing Password/Passphrase:
sudo cryptsetup luksChangeKey my_encrypted_drive.dd

• for more usage and help:
cryptsetup --help
man cryptsetup

Read more at Cryptsetup Homepage and Wikipedia .


note:
device => my_encrypted_drive.dd


Disclaimer

15 July 2015

Data Security: EncFS

Data Security: EncFS

ENCFS

according to the MAN page:

encfs - mounts or creates an encrypted virtual filesystem

..EncFS creates a virtual encrypted filesystem which stores encrypted data in the rootdir directory and makes the unencrypted data visible at the mountPoint directory. The user must supply a password which is used to (indirectly) encrypt both filenames and file contents...

    Advantages of EncFS:
  • Does not require root privilages.
  • Easy, simple to setup and carry.
  • No dependencies.
  • Able to enlarge storage as long as the HDD space is available.
  • Storage capacity not limited by fixed size encryption container like in truecrypt etc.



• Installing encfs :
on Debian system.
sudo apt-get install encfs

• We need to create two folder :
(one for encrypted folder and another for mount point/folder).
mkdir <ENCRYPTED FOLDER> <MOUNT FOLDER>
mkdir ~/encfs/ ~/mnt/


• Setup :
encfs ~/encfs/ ~/mnt/
thing to remember, the path must be absolute. ie- /home/user/mnt   or   ~/mnt   and not   mnt .
Since we are mounting it for the first time it'll prcode_innerompt for a setup and a password. it's fairly easy.

• Mounting encrypted folder :
encfs ~/encfs/ ~/mnt/
To encrypt any file(s), save them in the ~/mnt/ folder.it will be visible in plain sight.
if you look at the ~/enfs/ folder, you will see the encrypted raw files. that is the real files. Everything in ~/mnt/ is a mirror of the files in ~/encfs/.

• Unmounting the encrypted folder :
umount ~/mnt/


Extra's

• Displaying Info:
encfsctl <ENCRYPTED_FOLDER>
encfsctl info <ENCRYPTED_FOLDER>

encfsctl ~/encfs/
encfsctl info ~/encfs/


• Changing password:
encfsctl passwd <ENCRYPTED_FOLDER>
encfsctl passwd ~/encfs/


• For usage and option's :
encfs --help
man encfs

Read more at EncFS Homepage and Wikipedia .

04 July 2015

Unix tricks: Create a Portable Drive

Unix Tricks: Create a Portable Drive

Create a Portable Drive
unix tricks

Unix Tricks

• Create a blank file of 256 MB :
dd if=/dev/zero of=~/portable.drive bs=1M count=256

• Create an ext4  filesystem within the file:
mkfs -t ext4 ~/portable.drive
you can replace ext4 with ext2, ext3, vfat, msdos, minix etc.

• Create a mount point:
mkdir ~/mnt/

• Mount the File/Drive:
sudo mount -t ext4 ~/portable.drive ~/mnt/
  ••Now you can browse the drive••

• Unmount the drive:
sudo umount ~/mnt/

    Advantages
  • Easy to carry files stored in one container.
  • Good for hiding data and files from plain sight.if you share your computer with others
  • Usable across unix System.
    Disadvantages
  • No security or encryption set/applied.
  • Cannot be viewed, opened in Windows natively.


note:
The file created by this method can only be open and read by unix and unix-like system. Natively Windows cannot open this kind of file. but its possible to open it with Cywin
software.

letter-spacing:1px; letter-spacing:1px; Disclaimer

11 April 2014

Cowsay

Fun with Cowsay
As per unix manual, Cowsay is a configurable speaking/thinking cow. Cowsay is fun and bring relief when working with commands become long.
whatis cowsay
cowsay (6) - configurable speaking/thinking cow (and a bit more)

# try out this few commands
cowsay hello
cowthink hello
fortune | cowsay
fortune | cowthink
# Using others figures:
cowsay -f /usr/share/cowsay/cows/elephant.cow hello
fortune | cowsay -f /usr/share/cowsay/cows/elephant.cow
-f  is a file argument. it point to a cow file. and
/usr/share/cowsay/cows/elephant.cow  is the cow file.

cowsay -f /usr/share/cowsay/cows/vader.cow "The Empire strikes back"


# Here are few customised alias to make it easier to use cowsay. append the code below into .bashrc .

.bashrc
#cowsay alias
cowfolder=/usr/share/cowsay/cows

alias aptsay='cowsay -f $cowfolder/apt.cow'
alias beavis.zensay='cowsay -f $cowfolder/beavis.zen.cow'
alias bongsay='cowsay -f $cowfolder/bong.cow'
alias bud-frogssay='cowsay -f $cowfolder/bud-frogs.cow'
alias bunnysay='cowsay -f $cowfolder/bunny.cow'
alias calvinsay='cowsay -f $cowfolder/calvin.cow'
alias cheesesay='cowsay -f $cowfolder/cheese.cow'
alias cocksay='cowsay -f $cowfolder/cock.cow'
alias cowersay='cowsay -f $cowfolder/cower.cow'
alias daemonsay='cowsay -f $cowfolder/daemon.cow'
alias defaultsay='cowsay -f $cowfolder/default.cow'
alias dragon-andsay='cowsay -f $cowfolder/dragon-and.cow'
alias dragonsay='cowsay -f $cowfolder/dragon.cow'
alias ducksay='cowsay -f $cowfolder/duck.cow'
alias elephantsay='cowsay -f $cowfolder/elephant.cow'
alias elephant-in-snakesay='cowsay -f $cowfolder/elephant-in-snake.cow'
alias eyessay='cowsay -f $cowfolder/eyes.cow'
alias flaming-sheepsay='cowsay -f $cowfolder/flaming-sheep.cow'
alias ghostbusterssay='cowsay -f $cowfolder/ghostbusters.cow'
alias gnusay='cowsay -f $cowfolder/gnu.cow'
alias head-insay='cowsay -f $cowfolder/head-in.cow'
alias hellokittysay='cowsay -f $cowfolder/hellokitty.cow'
alias kisssay='cowsay -f $cowfolder/kiss.cow'
alias kittysay='cowsay -f $cowfolder/kitty.cow'
alias koalasay='cowsay -f $cowfolder/koala.cow'
alias koshsay='cowsay -f $cowfolder/kosh.cow'
alias luke-koalasay='cowsay -f $cowfolder/luke-koala.cow'
alias mech-andsay='cowsay -f $cowfolder/mech-and.cow'
alias meowsay='cowsay -f $cowfolder/meow.cow'
alias milksay='cowsay -f $cowfolder/milk.cow'
alias moofasasay='cowsay -f $cowfolder/moofasa.cow'
alias moosesay='cowsay -f $cowfolder/moose.cow'
alias mutilatedsay='cowsay -f $cowfolder/mutilated.cow'
alias ponysay='cowsay -f $cowfolder/pony.cow'
alias pony-smallersay='cowsay -f $cowfolder/pony-smaller.cow'
alias rensay='cowsay -f $cowfolder/ren.cow'
alias sheepsay='cowsay -f $cowfolder/sheep.cow'
alias skeletonsay='cowsay -f $cowfolder/skeleton.cow'
alias snowmansay='cowsay -f $cowfolder/snowman.cow'
alias sodomized-sheepsay='cowsay -f $cowfolder/sodomized-sheep.cow'
alias stegosaurussay='cowsay -f $cowfolder/stegosaurus.cow'
alias stimpysay='cowsay -f $cowfolder/stimpy.cow'
alias susesay='cowsay -f $cowfolder/suse.cow'
alias three-eyessay='cowsay -f $cowfolder/three-eyes.cow'
alias turkeysay='cowsay -f $cowfolder/turkey.cow'
alias turtlesay='cowsay -f $cowfolder/turtle.cow'
alias tuxsay='cowsay -f $cowfolder/tux.cow'
alias uniponysay='cowsay -f $cowfolder/unipony.cow'
alias unipony-smallersay='cowsay -f $cowfolder/unipony-smaller.cow'
alias vadersay='cowsay -f $cowfolder/vader.cow'
alias vader-koalasay='cowsay -f $cowfolder/vader-koala.cow'
alias wwwsay='cowsay -f $cowfolder/www.cow'

alias aptthink='cowthink -f $cowfolder/apt.cow'
alias beavis.zenthink='cowthink -f $cowfolder/beavis.zen.cow'
alias bongthink='cowthink -f $cowfolder/bong.cow'
alias bud-frogsthink='cowthink -f $cowfolder/bud-frogs.cow'
alias bunnythink='cowthink -f $cowfolder/bunny.cow'
alias calvinthink='cowthink -f $cowfolder/calvin.cow'
alias cheesethink='cowthink -f $cowfolder/cheese.cow'
alias cockthink='cowthink -f $cowfolder/cock.cow'
alias cowerthink='cowthink -f $cowfolder/cower.cow'
alias daemonthink='cowthink -f $cowfolder/daemon.cow'
alias defaultthink='cowthink -f $cowfolder/default.cow'
alias dragon-andthink='cowthink -f $cowfolder/dragon-and.cow'
alias dragonthink='cowthink -f $cowfolder/dragon.cow'
alias duckthink='cowthink -f $cowfolder/duck.cow'
alias elephantthink='cowthink -f $cowfolder/elephant.cow'
alias elephant-in-snakethink='cowthink -f $cowfolder/elephant-in-snake.cow' alias eyesthink='cowthink -f $cowfolder/eyes.cow'
alias flaming-sheepthink='cowthink -f $cowfolder/flaming-sheep.cow'
alias ghostbustersthink='cowthink -f $cowfolder/ghostbusters.cow'
alias gnuthink='cowthink -f $cowfolder/gnu.cow'
alias head-inthink='cowthink -f $cowfolder/head-in.cow'
alias hellokittythink='cowthink -f $cowfolder/hellokitty.cow'
alias kissthink='cowthink -f $cowfolder/kiss.cow'
alias kittythink='cowthink -f $cowfolder/kitty.cow'
alias koalathink='cowthink -f $cowfolder/koala.cow'
alias koshthink='cowthink -f $cowfolder/kosh.cow'
alias luke-koalathink='cowthink -f $cowfolder/luke-koala.cow'
alias mech-andthink='cowthink -f $cowfolder/mech-and.cow'
alias meowthink='cowthink -f $cowfolder/meow.cow'
alias milkthink='cowthink -f $cowfolder/milk.cow'
alias moofasathink='cowthink -f $cowfolder/moofasa.cow'
alias moosethink='cowthink -f $cowfolder/moose.cow'
alias mutilatedthink='cowthink -f $cowfolder/mutilated.cow'
alias ponythink='cowthink -f $cowfolder/pony.cow'
alias pony-smallerthink='cowthink -f $cowfolder/pony-smaller.cow'
alias renthink='cowthink -f $cowfolder/ren.cow'
alias sheepthink='cowthink -f $cowfolder/sheep.cow'
alias skeletonthink='cowthink -f $cowfolder/skeleton.cow'
alias snowmanthink='cowthink -f $cowfolder/snowman.cow'
alias sodomized-sheepthink='cowthink -f $cowfolder/sodomized-sheep.cow'
alias stegosaurusthink='cowthink -f $cowfolder/stegosaurus.cow'
alias stimpythink='cowthink -f $cowfolder/stimpy.cow'
alias susethink='cowthink -f $cowfolder/suse.cow'
alias three-eyesthink='cowthink -f $cowfolder/three-eyes.cow'
alias turkeythink='cowthink -f $cowfolder/turkey.cow'
alias turtlethink='cowthink -f $cowfolder/turtle.cow'
alias tuxthink='cowthink -f $cowfolder/tux.cow'
alias uniponythink='cowthink -f $cowfolder/unipony.cow'
alias unipony-smallerthink='cowthink -f $cowfolder/unipony-smaller.cow'
alias vaderthink='cowthink -f $cowfolder/vader.cow'
alias vader-koalathink='cowthink -f $cowfolder/vader-koala.cow'
alias wwwthink='cowthink -f $cowfolder/www.cow'


# Open terminal and try them:
aptsay hello world.
ducksay hello.
elephantsay "i am round."
elephantthink "am i round!"
duckthink "Where are all the fish?"
tuxsay welcome
fortune | tuxsay
fortune | tuxthink
date | cowsay
whatis cowsay | cowthink
echo "i'm `whoami`" | tuxsay
bunnysay hello.


Time Counter

Time Counter

Time Counter

Create a time counter using Shell scripting.

# Create a file  time.txt  in home folder (any folder is ok). put '0' (zero) in it as second (starting value of time).

time.txt
0


# Create a  time.sh  script (in the same folder) and put this code in it.
#!/bin/sh
#file: time.sh
#description: keep track of time spend on computer.

file=time.txt

if [[ -f $file ]]; then
old_time=$( cat $file ) && new_time=$[ $old_time + 60 ] && echo $new_time > $file ;
else
echo '0' > $file ;
fi;
This script will take stored time value from  time.txt  and add 60 seconds to it when run.
So if the current stored time value is '0' (zero), it will add 60 seconds to it. and so on.


# Now we will run this script with crontab. Open Terminal and edit crontab:
crontab -e

..and add this line to the bottom of the file:
* * * * * /bin/bash ~/time.sh
This will make the  time.sh  to run and update  time.txt  simulteneously every minute.


# put this code in .bashrc file (found in home folder). with this we can check the time on terminal..
counter() {
second=$( cat ~/time.txt ) ;
day=$[ $second/86400 ] ;
hour_remain=$[ $second%86400 ] ;
hour=$[ $hour_remain/3600 ] ;
minute_remain=$[ $second%3600 ] ;
minute=$[ $minute_remain/60 ] ;

echo $day days $hour hours $minute minutes since 2014 April 12th.

}


# Open Terminal and enter counter:
0 days 0 hours 44 minutes since 2014 April 12th.


12 March 2014

Hidden power of Android

android

Hidden Power of android.

Every android phone comes with a Busybox , which provides several unix tools. (Android use a Linux kernel. ). unfortunately android does not provide a shell or command interpreter. like xterm in Debian/Ubuntu. user will have to install them manually. few of it are. • Below are some useful command found in android:

cal displays a calendar and the date of Easter
dd convert and copy a file
df , du report file system disk space usage
dos2unix , unix2dos convert file from one format to another.
ftpget , ftpput , tftp File transfer client & server.
httpd A barebone web server.
ifconfig configure a network interface
ip show / manipulate routing, devices, policy routing and tunnels.
md5sum , sha1sum , sha256sum , sha512sum compute and check MD5 , SHA1SUM , SHA256SUM , SHA512SUM message digest
nc The swiff army knife of network mapping.
netstat Display network connections, routing, tunnel etc.
ping , ping6 send ICMP ECHO_REQUEST to network hosts
ps Display process
sh , ash Shell or Command interpreter
sqlite3 A command line interface for SQLite version 3
telnet , telnetd A Telnet client & server.
traceroute , traceroute6 Trace the route to HOST
top Display top process
touch change file timestamps
udhcpc , udhcpd DHCP client & server.
uname Get system or kernel information
uptime Tell how long the system has been running.
vi Text Editor
wget The non-interactive network downloader.
who show who is logged on
whois client for the whois directory service


Other commonly use command:
awk , basename , id , hostname , clear , cat , date , diff , dirname , dmesg , echo , dnsdomainname , env , false , find , hostid , head , grep , less , ln , ls , mkdir , logname , more , mv , pwd , sleep , sort , rm , rmdir , sed , renice , reset , tail , tee , test , true , uniq , which , whoami , wc , yes .

Here are few example:

ping -c 5 google.com
sqlite3 foo.db
Web Server:
busybox httpd -h /mnt/sdcard/www/ -p 8888
Download Manager:
busybox wget -c www.example.com/map.png
Telnet Server:
busybox telnetd
busybox telnet 127.0.0.1
busybox whois www.google.com
busybox uname -a
busybox top -d 2
dd if=pic1.jpg of=pic2.jpg
busybox cal 2014
busybox netstat -tun


22 February 2014

Installing ADB in GNU/Linux

adb

Making ADB work in Linux (Debian/Ubuntu)

  1. Install Android Debug Bridge for GNU/Linux.

    • for Debian & DEB packages:
    sudo apt-get install android-tools-adb

    • for Redhat & RPM packages:
    sudo yum install android-tools-adb


  2. Connect android phone.
    lsusb
    Bus 001 Device 008: ID 058f:6366 Alcor Micro Corp. Android
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Find the corresponding line for your android phone.
    The Vendor & Product ID will be in XXXX:XXXX format. In our example the ID's is 058f:6366 .
    058f = VendorID.
    6366 = ProductID.


  3. Create Rules.
    sudo gedit /etc/udev/rules.d/51-android.rules
       you can use vi, nano, pico or any text editor in place of gedit.

    append the code to the file.
    SUBSYSTEM=="usb", ATTR{idVendor}=="058f", ATTR{idProduct}=="6366", MODE="0666", GROUP="plugdev"


  4. Create adb file in home ( ~ ) folder.
    mkdir ~/.android
    ( if not already created. )
    touch ~/.android/adb_usb.ini
    echo '0x6366' >> ~/.android/adb_usb.ini


  5. Restart udev.
    sudo service udev restart
    adb kill-server
    adb start-server


  6. Reconnect the Phone.
    You may need to disconnect and reconnect the phone again. and wait for a couple of minute to get it detected.
    adb devices
    List of devices attached
    19761202 device
    45024745 device




# The short way.

Copy this code into the terminal (replaces id's) and run it.

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="6366", ATTR{idProduct}=="058f", MODE="0666", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/51-android.rules && mkdir ~/.android/ && touch ~/.android/adb_usb.ini && echo '0x6366' >> ~/.android/adb_usb.ini && sudo service udev restart && adb kill-server && adb start-server && adb devices
Replace the VendorID & ProductID with the one you got....



07 October 2013

Updating Linux Kernel

updating kernel

how to update ubuntu kernel to 3.10

The current long term linux kernel is 3.10 (correct as of 2013). so it's a good choice for previous longterm kernel user to jump to 3.10 for it bring many new features and improvement.
    Advantages of longterm kernel 3.10 are:

  • Tickless Timer
    Improve CPU performance and latency by reducing tick from 1000 to 1 per second.
  • Tail loss probe
    Improve network latency.
  • Bcache
    HDD performance improvement, by allowing SSD to act as cache.
  • ARM big.LITTLE support
  • MIPS KVM support
  • Memory, filesystem, Networking, crypto, Security, Virtualization Improvement
  • and many more...

Installing the latest kernel

# download the latest kernel in 'deb' format from kernel.ubuntu.com :

for 32-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb

for 64-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb

# install by running:
sudo dpkg -i *.deb

See The Changes

Unfortunately, you will have to reboot your computer to see the changes. the new kernel shall be visible in GRUB menu during bootup. Generally, GNU/Linux does never need to reboot for software, library etc et al to work after install. But kernel will be an exception.

# in rare case if it does not appear or update the grub menu itself:
sudo update-grub

note: this method will work on ubuntu and its derivatives.

28 September 2013

An Intro on SQLite

SQLite is a Relational Database Management System (RDMS). but unlike other RDMS, it does not require a ceentral server to be run or client to access the process. and lightweight. due to its small size it is use in various application, Operating System, Embedded System etc. The best part of it, it is in Public Domain. Which mean any software maker, individual or software company can use and impliment it into their application. SQLite is use in various open source and closed source system.

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
      - sqlite.org

    SQLite is use in various software appication:
  • Mozilla Firefox
  • Google Chrome
  • Opera
  • Ruby On Rails
  • Adobe System
  • and more..
    SQLite is also use in various OS:
  • NetBSD
  • OpenBSD
  • Apple iOS
  • Google Android
  • Windows Phone 8
  • Symbian OS
  • BlackBerry 10 OS
  • and more..
Despite it small size, it implement almost all SQL standard query. but few features are missing, like 'ALTER TABLE'.

A short tutorial

# Checking SQLite version:
sqlite3 -version
-- Loading resources from /home/user/.sqliterc

3.7.15.2 2013-01-09 11:53:05 c0e09560d26f0a6456be9dd3447f5311eb4f238f

# Getting Usage help:
sqlite3 -help

# Create a database 'foo.db' :
sqlite3 foo.db
This will create the foo.db (empty database) and drop to sqlite shell.
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

# To create a table, we will run an SQL query:
sqlite> CREATE TABLE person (name VARCHAR(12), age VARCHAR(3));
a table 'person' will be created with column name & age.

# Display all tables in the database:
sqlite> .tables
Or similar tables..
sqlite> .tables ??TABLE??

# Adding data to table:
sqlite> INSERT INTO person VALUES ('jack', '50');
sqlite> INSERT INTO person ('name') VALUES ('henry');

# Displaying the inserted data:
sqlite> SELECT * FROM person;

SQLite can also read SQL query from a text file.

sql.txt
select * from person;
select * from person where name='john';

# To run SQL query that is given in sql.txt .
sqlite> .read sql.txt

To manipulate any data in the databases the user will have to run SQL query. This author guess that the reader has prior knowledge of SQL query.

# To exit SQLite shell:
sqlite> .quit
sqlite> .exit


23 September 2013

Making USB Modem work in GNU/Linux

the short way

Short tutorial for those who donot have all the time in the world to read a lengthy tutorial.
Open ' Terminal ' and run..
eject /dev/sr1
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note the ID corresponding to USB/3G Modem.
sudo modprobe usbserial vendor=0x24e3 product=0x3e76


the long way

This tutorial will work for most 2G, 3G, 4G or any USB Modem under GNU/Linux using debian/ubuntu.

# Before inserting your usb modem. Open 'Terminal' and run the following command:
ls /dev/sr*
It'll output something like:
/dev/sr0
sr0 is mostly CD/DVD-Drive or any Serial Drive connected.

# Now insert your USB Modem and run the command again..
ls /dev/sr*
/dev/sr0 /dev/sr1
Note the extra serial device (sr1). it is your usb modem internal storage, because when attached they are dectcted as storage devices. It's explained in 'man usb_modeswitch'.
...When plugged in for the first time, they act like a flash storage and start installing the Windows driver from there. If the driver is already installed, it makes the storage device disappear and a new device, mainly composite with modem ports, shows up.

On Linux, in most cases the drivers are available as kernel modules, such as "usbserial" or "option". However, the device shows up as "usb-storage" by default...


# In 'Terminal':
lsusb
Bus 001 Device 004: ID 24e3:2205 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
note the ID corresponding your USB 3G Modem.

# Eject the modem storage:
eject /dev/sr1
..and..
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
It will show a new ID for the Modem.
24e3:3e76
24e3 is VendorID. 3e76 is ProductID of the modem.

# Make the modem visible to the system by running modprobe:
sudo modprobe usbserial vendor=0x24e3 product=0x3e76
Replace the ID with your Modem ID.

Wait a minute for the modem to appear in Network Manager.


04 May 2013

Screw yourself with IFCONFIG



If you does not know what in the world is  ifconfig !    SCREW YOURSELF!   for your kind information  ifconfig  is a network interface configuration tool.

Open Terminal:
ifconfig
For  Windows, command will be slightly different:
ipconfig
Output:
eth0      Link encap:Ethernet  HWaddr 00:1d:60:06:cc:2d  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:852 errors:0 dropped:0 overruns:0 frame:0
          TX packets:852 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:64720 (64.7 KB)  TX bytes:64720 (64.7 KB)

Show all interfaces:
ifconfig -a

Display information for eth0 interface:
ifconfig eth0


The fun begin..

Take down the eth0 interface:
ifconfig eth0 down
This will deactivate eth0.

Change the IP address of eth0:
ifconfig eth0 111.111.0.0

Change the hardware address of eth0:
ifconfig eth0 hw ether aa:aa:aa:aa:aa:aa

Bring up the interface eth0:
ifconfig eth0 up

Now run ifconfig..
ifconfig eth0
Output:
eth0      Link encap:Ethernet  HWaddr aa:aa:aa:aa:aa
          inet addr:111.111.0.0  Bcast:255.255.255.255  Mask:0.0.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

These are few example of ifconfig. more option and argument can be found in man page.
man ifconfig


27 April 2013

more SQL tutorial



Let us build a database  'test' with table  'person' inside it, having column  name, age, gender. see how to do this


Insert a line into table:
INSERT INTO person (name, gender) VALUES ('omphu', 'female')
This will add a new line or data into the table  'person' on column  name, gender with value omphu, female respectively and will leave the value of age blank.

Select line using WHERE:
SELECT * FROM person WHERE gender='female'

Select specific column:
SELECT name FROM person WHERE gender='male'
This will output the value of column name where gender is female.

Specify more argument to refine search:
SELECT name, age FROM person WHERE age='21' AND gender='male'
Will output result if this two condition are true,  age & gender.

SELECT name, age FROM person where age='21' OR gender='female'
This will output result if one of the two condition is true,  age & gender.

Limit output to 5 result:
SELECT * FROM person LIMIT 5

Sort result by Ascending/Descending order:
SELECT * FROM person ORDER BY name ASC
SELECT * FROM person ORDER BY name DESC

Query name which contain the letter  a.
SELECT * FROM person WHERE name LIKE '%a%'

Query only unique name:
SELECT DISTINCT(name) FROM person
This query is useful when we have many duplicate data of the same value.

Count total line in the table:
SELECT COUNT(name) FROM person

19 April 2013

Basic SQL tutorial



INTRO:
SQL is a programming languages designed for managing data. It is used for data storage or database storage. MySQL is the most popular among database management storage system. Others are Oracle, Windows Access, PostgreSQL, SQLite etc. Database are use from Office productivity to storage of various data type.

This tutorial will cover all the basic of the above and more database system..

SQL look like this..
SELECT * FROM table

Create a database:
CREATE DATABASE test
This will create a database with name  'test'.

Create a table:
CREATE TABLE person ( `name` VARCHAR(12), `age` VARCHAR(3), `gender` VARCHAR(6) )
This will create a table with name  'person' having column  name, age, gender.

Add a data to table:
INSERT INTO person (name, age, gender) VALUES ('anil', '18', 'male')
This will add a line into the table  person  to the column  name, age, gender  with value  anil, 18, male  respectively.

Check if the data/line has been added:
SELECT * FROM person
Output:
name age gender
anil 18 male


Note:
* the number in  VARCHAR(12)  signify only 12 characters will be saved and rest omitted. If we enter a name  'verylonglongname' (16 char), the saved name will only be  'verylonglong' (12 char), last 4 char omitted.


11 April 2013

BACKUP FACEBOOK PROFILE



Facebook is the leading social network, there is no doubt. It has more than 1 billion registered user. There is hardly any one who had not heard (or using) it.

This tutorial is an example on how to backup/download 'facebook profile' (our own profile). Frustated at not finding a single tutorial on how to backup my user profile. i went ahead and created this tutorial. back to the point, we will use 'cURL' (and 'wget') for this purpose as it is available for almost all system.

Facebook data are available from 'https://graph.facebook.com'. Basic info like id, username, name, link, gender & locale are available publicily. Throw in an access token you have all data that is in public or visible to friends. Example below:
https://graph.facebook.com/jor.teron

Required:
* cURL or wget
* User ID (UID)
* facebook access_token
* Basic idea on FQL and FQL tables (optional)

This method work by invoking graph explorer...
https://graph.facebook.com/fql?q=FQL_QUERY&access_token=ACCESS_TOKEN
where  FQL_QUERY  is the FQL query implemented by facebook. If  FQL_QUERY  is..
select description from group where gid=XXXXXXXX
..then url will be like.
https://graph.facebook.com/fql?q=select+description+from+group+where+gid=XXXXXXXX&access_token=ACCESS_TOKEN


STEP TO FOLLOW:
1) Goto Graph API Explorer, https://developers.facebook.com/tools/explorer. Login if necessary. Click 'Get Access Token' button. Select appropriate permission. save it. Copy the access token (those jumbled alphabet).

2) Note down your UID.

3) Open 'Command Prompt' and type in the following.
for cURL:
curl --user-agent 'Firefox 10' \
--output file.txt \
"https://graph.facebook.com/fql?q=select+uid,username,name+from+user+where+uid=UID&access_token=ACCESS_TOKEN"

for wget:
wget --user-agent='Firefox 10' \
--output-document=file.txt \
"https://graph.facebook.com/fql?q=select+uid,username,name+from+user+where+uid=UID&access_token=ACCESS_TOKEN"

note:
* Replace UID and ACCESS_TOKEN with its respective values you got in step 2 and 1 respectively.
* ACCESS_TOKEN is valid only for 1 hour, so you will need to get it (again) later if needed.

In the above example it'll download User Profile (containing id, username, name) and save it to 'file.txt'. You can specify more column if needed.


To download photos:
curl --user-agent 'Firefox 10' \
--output photo.txt \
"https://graph.facebook.com/fql?q=select+src_big+from+photo+where+owner=UID&access_token=ACCESS_TOKEN"
Sort out photos links using grep, sed, awk or regex to download them. In these way one can download facebook data from profile to photos, comments to likes, pokes to messages etc.


If FQL intimate you, there is an easier way to fetch data by using Graph Search....
https://graph.facebook.com/USER?fields=GRAPH_OBJECT&access_token=ACCESS_TOKEN
Example:
https://graph.facebook.com/jor.teron?fields=id,username,name&access_token=ACCESS_TOKEN

This tutorial will benefit those who want to backup their facebook data. Alternatively if you find this process hard to follow you can use facebook own feature 'Copy Facebook'.




12 March 2013

netstat usage example


Sometimes we need to know who are connected to our system. this can be to find malware or botnet that may be connecting us to somewhere. or some trojan stealling our data. end point is we need to find out network activities. this can be done with 'netstat'.


running netstat command will display all connection in a unix system.

netstat



to find out all TCP connection with netstat.

netstat -t



to find out all TCP and UDP connection...

netstat -tu



to find out all connection initiated by a program through TCP..

netstat -tp



to output all information in numeric format..

netstat -n



to find out all incoming connection and listening to..

netstat -l



you can also combine them..

netstat -tn



this will output TCP connection in Numeric format.

netstat -tupn


this will output all connection made by a software program in Numeric format.


these above are few example of netstat. you can check out man page for more.


put this script inside your bash profile in /home/user/.bashrc

#!/bin/bash

connection()
{
cat=$( netstat -tun | sed '1,2 d' | awk '{print $5}' | sed -r 's/(.*)\:(.*)/\1/g' | sort | uniq );

for i in $cat; do
netname=$( whois $i | grep -i netname | awk '{print $2}' );
echo "connection with: $netname ($i)";
done;
}


now open 'terminal' and type 'connection'.

this is just one stupid script. you can build better than this.
godspeed.


11 November 2012

automate home folder backup and software install script

unix user is notorous for oftenly changing Operating System (OS) or distro hopping. since new/increment version are realeased more frequently. it become significant / necessary to update to a newer release.

installing and configuring is time consuming if you have lots of software to install, say 30 or more. even more if you spend time playing solitaire or 0AD (no i had not played 0AD yet).

the saving grace in this situation is to create a script that will automate this work. first backup/copy your home folder (along with hidden folder).

below is the script (bash) to automate install of software after fresh install of new OS (Operating system).
the script for backing up setting from home folder is given below.



#add the name of software you want to install here seperated by [space].
cd $HOME
app_list="firefox gcolor2 gimp vlc";

for app in $app_list; do
if [[ `which $app` == "" ]]; then
echo "installing $app.....";
apt-get -y install $app; #install the app
else
echo "$app is already installed (skipping)."; #app is already
installed
fi;
done;


#script for backing up setting (from home folder).
cd $HOME ;
folder=backup ;
mkdir $folder ;
dir=$HOME/$folder/ ;

for i in `ls -A`; do
if [[ $i == .* ]]; then
if ( [[ $i == .thumbnails ]] || [[ $i == .cache ]]
|| [[ $i == .gvfs ]] || [[ $i == .local ]]
) ; #add more folder name that you don't want to backup then echo "Not copied $i";
else
echo "Copying $i";
cp -r $i $dir$i ;
fi;
fi;
done;

tar -cf backup.tar ./$folder ;
rm -r ./$folder ;




ps- sorry for my bad english. i'm still new in scripting. this is my first post.