Daily Archives: 18 February 2012

Ubuntu Linux: How to register machine IPs and domain name to web-server using php

First of all you will need a page the will keep record of the registrations.

To do the paste the following code in a *.php file on a php-enabled webserver:


if (isset($_GET["ip"]) && isset($_GET["name"]))
  echo "Current Time " . gmdate("d/m/Y H:i:s e", $_SERVER['REQUEST_TIME']) . " IP " . $_GET["ip"] . " Hostname " . $_GET["name"] . "!<br/>"; 
  $file=fopen("cookies.txt","a") or $file=fopen("log.txt","x");
  fwrite($file,"Time " . gmdate("d/m/Y H:i:s e", $_SERVER['REQUEST_TIME']) . " IP " . $_GET["ip"] . " Hostname " . $_GET["name"] . "\n" );
  echo "Welcome Murloc!<br />";
  echo "Following the SSH Login Log File:<br /><br />";
  $file=fopen("log.txt","r") or $file=fopen("cookies.txt","x");
    echo fgets($file). "<br />";
  echo "Your IP is ".$_SERVER['REMOTE_ADDR']. "<br />Current Time " . gmdate("d/m/Y H:i:s e", $_SERVER['REQUEST_TIME']) . "<br /><br />";
  echo "Bye Bye Bob<br />";

The above php script will store your IP and Hostname if you provide them on the URL along with the time that the event happened and if you do not then it will list the registered IPs.

NOTE:Not sure how safe this code is

In order to invoke it / send you IP and hostname, issue form bash the following:

IPs=`ifconfig  | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}'`
wget "http://www.example.com/ip.php?ip=$IPs&name=$HOSTNAME" -o /dev/null



Ubuntu Linux: How to Resize and add Label to a many picture files 1

Lets say you have a ton of pictures or photos that you want to resize and add a semi-transparent label at the bottom of this bulk of files and even rename them using a pattern based on a unique number.

You can either do this manually or by using imagemagick. If you chose the second way follow these steps:

First of all install it, from bash/terminal call the following:

sudo apt-get install imagemagick

When that command is successfully completed, navigate to the location that the pictures are and once you are there:

In order to resize all pictures then issue the following command (in this example we make all pictures at most 1200px long or 1200px tall and keep the aspect ratio) :

mogrify -resize 1200 *

NOTE: It will affect the original files! So if you want to keep them make sure to copy them elsewhere BEFORE issuing the above command.

After the above is done, you can issue the following set of commands to:

  1. Get each file and find it’s dimensions (which later will be used for the label creation)
  2. Rename all pictures following the number based pattern
  3. Add a semitransparent label containing custom text at the bottom
counter=0; for i in *;
do let counter=counter+1;
width=`identify -format %w "$i"`;
convert -background '#0008' -fill white -gravity center -size ${width}x30 caption:" Some Arbitrary Text " "$i" +swap -gravity south -composite NewFileName.`printf %03d $counter`.jpeg;

This command will preserve the original files.
All together with printing the file that is being processed as debuging information:

mogrify -resize 1200 *; counter=0; for i in *; do let counter=counter+1; echo $i; width=`identify -format %w "$i"`; convert -background '#0008' -fill white -gravity center -size ${width}x30 caption:" Some Arbitrary Text " "$i" +swap -gravity south -composite NewFileName.`printf %03d $counter`.jpeg; done

Sample/Result Photos: