Create AutoIncrement column/field in Apache Derby
While creating a table a particular column / field can be made autoincrement as : CREATE TABLE students ( id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(24) NOT NULL, address VARCHAR(1024), CONSTRAINT primary_key PRIMARY KEY (id) ) ; The value of an autoincrement column increments automatically with… Read More »
PHP redirect – go back to previous page
PHP Format numbers to Indian Numerical System
The numerical system used in India differs from the Western system in terms of the placement of the thousands separator. Example : Number -> 1000000 Indian System -> 10,00,000 (Ten Lakh) Western System -> 1,000,000 (1 Million) While echoing numbers in PHP it is possible to format numbers with such separators using functions like number_format…. Read More »
How to create .deb file from source using CheckInstall on Ubuntu / Debian
Many software applications for linux are available in the form of source code which needs to be compiled. The general process to compile such software is by running the configure, make and make install commands. After the install process the files get installed in the system directories and the software can be run from the… Read More »
How to get Screen Resolution 1440×900 in Ubuntu
Ubuntu 9.04 did not detect the native resolution of my new LCD monitor which was 1440×900. Fix : 1. Get the Modeline – The first step is to get the modeline for the specific resolution and refresh rate using the gtf command. Here is a quick example: $ gtf 1440 900 75 # 1440×900 @… Read More »
How to Code Raw Sockets in C on Linux
Raw tcp sockets in C Raw sockets can be used to construct a packet manually inside an application. In normal sockets when any data is send over the network, the kernel of the operating system adds some headers to it like IP header and TCP header. So an application only needs to take care of… Read More »
How to code a SYN Flood DOS attack program in C on Linux
TCP/IP 3-way handshake is done to establish a connection between a client and a server. The process is : 1. Client –SYN Packet–> Server 2. Server –SYN/ACK Packet –> Client 3. Client –ACK Packet –> Server The above 3 steps are followed to establish a connection between source and destination. SYN Flood DOS attacks involves… Read More »
Top 15 Best Free Games to play on Ubuntu / Linux Mint
PHP: Get visitor’s location, city, country from IP address
Ip to Location Many applications need to get information about the geographical location of the user/visitor on their websites. This can be done in many ways. There are online services like ipinfodb and geoio that provide web based api to get the geolocation information about a given ip address. Services like Maxmind geoip provide free… Read More »
Parse and change date format in php
Parsing dates Most php applications need to parse dates and convert them to timestamps for example. Parsing is also necessary to convert the date into a more standard format like yyyy-mm-dd which can be stored in a database like mysql. Mysql database stores dates in the format yyyy-mm-dd like 2009-04-15. However humans are more used… Read More »
Restore Mysql Database from a sql or zip file using PHP
In a previous post we learnt how to inside php. In this example the same zip file would be used to restore the database. Code // Function to restore from a file function restore($path) { $f = fopen('restore/temp.sql' , 'w+'); if(!$f) { echo "Error While Restoring Database"; return; } $zip = new ZipArchive(); if ($zip->open($path)… Read More »
Backup mysql database with php and zip it
Many php applications prefer to backup the mysql database from within the application and save it as an archive. The mysqldump commandline utility can be used to perform this function of backing up a mysql database as sql file. The command would be like this : mysqldump –user=$username –password=$password –opt $db_name > $dir/backup.sql The above… Read More »
How to code a TCP Connect Port Scanner in C with Winsock
Tcp connect port scanning TCP connect() scanning is the most basic form of TCP scanning. The program performs a connect() command on those ports of the target machine which are to be checked. If the port is open then the connect() command will succeed and a connection will be established. If the port is closed… Read More »
How to Code a Port Scanner in C on Linux
Port scanning A port scanner is a program that checks for open network ports on a local or remote machine. For example, if a machine is running an http webserver then it has port 80 open. So by scanning for open ports on a machine, we can find what server applications are running on it…. Read More »
Php – parse text and convert urls into hyperlinks
The following function will parse a given text and convert all the urls into links. It does this using regular expressions. It converts email addresses to mailto links as well. Code function parse_links($str) { $str = str_replace('www.', 'http://www.', $str); $str = preg_replace('|http://([a-zA-Z0-9-./]+)|', '<a href="http://$1">$1</a>', $str); $str = preg_replace('/(([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6})/', '<a href="mailto:$1">$1</a>', $str); return $str; }
How to code a Packet Sniffer in C with Libpcap on Linux
Libpcap Libpcap is a packet capture library for linux which can be used to sniff packets or network traffic over a network interface. Pcap Documentation gives a description of the methods and data structures available in the libpcap library. To install libpcap on your linux distro you can either download the source from the website… Read More »
How to code Packet Sniffer in C with Sockets on Linux
Packet sniffer Packet sniffers are programs that intercept the network traffic flowing in and out of a system through network interfaces. So if you are browsing the internet then traffic is flowing and a packet sniffer would be able to catch it in the form of packets and display them for whatever reasons required. Packet… Read More »
How to fix slow Internet on Ubuntu when using a switch
Switches, Routers, Wires and speed As usual internet was fast on ubuntu as it used to be till I needed to plug more PCs into the adsl route lying nearby. After connecting all computers and the adsl router to a switch I noticed that on one of the PC (Ubuntu 8.04) internet became really slow…. Read More »
Install Postgresql, phpPgAdmin and pgadmin on Ubuntu
Install Postgresql , phpPGAdmin and pgadmin 3 can be installed from synaptic. $ sudo apt-get install postgresql phppgadmin pgadmin3 After installation some configuration needs to be done. First of all setup the password of the user ‘postgres’ which is the default user of postgresql. Type the following in the terminal $ sudo -u postgres psql… Read More »