Tuesday, May 4, 2010

Fedora 12 on LG R560 laptop

I installed Fedora 12 on my new Laptop (LG R560), Below is the status and the resolutions of the issues I faced:

Installation:
No problem was found, Partitions, Installation, Everything worked as expected.

Power Up:
Worked fine.

WIFI:
Didn't worked, Tried to activate the WiFi adapter (Fn + F6) with no luck, According to the Laptop spec its contain Intel WiFiLink 5300, I installed the driver (iwlwifi-5000-ucode-8.24.2.12), But with no luck.
After some research I found that I have RaLink RT2860 and not Intel, So the problem was solved by installing the
kmod-rt2860-PAE.i686 package from the rpmfusion-free-updates repository and reboot.
Now, Fn+F6 do activate the WiFi adapter and I succeeded to connect my Wireless network.

Wednesday, November 25, 2009

KDE 4.3 and Conky

While using Conky (http://korenofer.blogspot.com/2008/11/my-conky-configuration.html) with KDE 4.3 There is a background problem, instead of transparent background the Conky seems to have a black background which hide the actual desktop.
The problem is that KDE draw the wallpaper on the plasma desktop instead of the root window, When Conky try to get the background from the root window, It only get the black color.
To fix this, We can use the "feh" command which can set the background image to a specific file.
What I'm having now is the following script:
#! /bin/bash
feh --bg-scale `grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | tail --bytes=+11`
sleep 15
conky -&


Some explanation:
The `grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | tail --bytes=+11` command will get the current desktop picture file name.
feh --bg-scale Is used to set the background image using a file name.

And then we can call Conky (The sleep 15 is for use this script during the KDE start up,this way we make sure the desktop is up before we are trying to show the Conky output on the screen).

 

Sunday, September 6, 2009

Perl inheritance - The basics

We can implement inheritance in Perl using packages (as our "classes").
The following sample will demonstrate package inheritance:

First, Lets create our base package, in this sample, I have created a simple logger package which has a constructor and a "print" method:

# Module Name

package mylogger;
## Constructor
sub new {
  print "mylogger  :new\n";
  my $package = shift;
  return bless({}, $package);
}
## Print Method
sub print
{
    print "mylogger  :print - " . $_[1] . "\n";
}
1;

If my main application will call this module:
use mylogger;
my $myLogger = mylogger->new();
$myLogger->print("Hello world");

The Ouput will be as following:
mylogger  :new
mylogger  :print - Hello world

Lets now create a newer logger which inherit the previous one and print the message time and date:
# Module Name
package newlogger;
use mylogger;
## Inherit from mylogger
our @ISA=qw(mylogger);
sub print
{
    print "newlogger :print - " . $_[1] . " (at ". localtime(time) .  ")\n";
}

Now, If we will call the new loggers following:
my $newlogger = newlogger->new();
$newlogger->print("Hello world");

The following output will appear:
mylogger  :new
newlogger :print - Hello world (at Sun Sep  6 22:00:52 2009)

OK, What happen here?
The first module is straight-forward, Please refer to my previous entry regarding Perl modules,
The second one act as following:
When newlogger->new() is being called, Perl start looking for the "new" method in the newlogger package, Since we don't have one, Perl try to look the requested method in the packages which are listed in the @ISA list.
Since we have a "new" method in our "mylogger" package, Perl call this function and do the following:
First its print the "mylogger  :new\n"  message.
Second its return a reference (by using bless) to the inserted package, which is "newlogger".

And since the "new" function returned a "newlogger" object, When the app call the $newlogger->print method, its actually calling the new method with the time stamp.







Sunday, April 19, 2009

Creating and Using Perl modules

A little example to demonstrate how to create and use Perl module in Perl application.

First we will create the module:

The module file extension should be “pm”, and it should contains:
#MODULE_START
# Module Name
package Comm;
#######################################################################
## Module related arguments

use 5.006;
## Constructor
sub new {
    my $package = shift;
    return bless({}, $package);
}

#######################################################################3
## My Code

sub printHello()
{
    print "Hello World";
}

#MODULE_END

Now, Lets use the module in our Perl application
#APP_START
#/usr/bin/perl;
use strict;
use warnings;
# My Module
use Comm;

# Module creation
my $myModule= Comm->new;
$
myModule->printHello;

#APP_END

Few Notes about this sample:

  1. The application should know the module path.

  2. As you can see, I'm calling the module function with the module prefix (Conn->....), To avoid it we can use the “Exporter” inside the module to export its function directly,









Tuesday, February 24, 2009

keys functions issue with VMware 6.5

Since I installed VMware 6.5 workstation on my Fedora 10 host, None of the following keys worked:
  • Arrow keys
  • Home
  • End
  • Page down/UP
  • Insert
  • Delete
Some keys didn't worked at all while others was mapped to wrong function (e.g. : arrow up opened the "save screenshot" dialog.

I have tried several solution (xorg.conf, evdev driver ) with no use, Till I found the following (simple) solution:

echo "xkeymap.nokeycodeMap = true" >> ~/.vmware/config

And thats it, No more keys issue :-)

Saturday, February 14, 2009

Simple UDP port scanner in perl - ICMP unreachable

One way to scan the open UDP ports on a remote machine, Is to send an UDP packets to its ports and listen the ICMP "destination unreachable" responses, If we received that message, its mean that the port we have tried to send to is currently close.


In the following Perl code I will send an UDP packet to each port, and if I won't receive the ICMP destination unreachable packet I will assume the scanned port is open:


#!/usr/bin/perl

use Net::Ping;
use IO::Select;
use IO::Socket::INET;

# IP address to scan
my $ip = '10.0.0.1';

# First we will send a ping to make sure the scanned host is exist
my $p = Net::Ping->new( "icmp", 1, 64 );
if ( $p->ping($ip) ) {
print "$ip answered ping , Start scanning ....\n";
} else {
print "$ip did not answer ping\n";
exit 5;
}
# Time to wait for the "destination unreachable" package.
my $icmp_timeout=2;
# Create the icmp socket for the "destination unreachable" packages
$icmp_sock = new IO::Socket::INET(Proto=>"icmp");
$read_set = new IO::Select();
$read_set->add($icmp_sock);

# Buffer to send via UDP
my $buf="hello";

# Scan all the ports .....
for ( $i=1 ; $i <= 65535 ; $i++ ) { # Create UDP socket to the remote host and port
my $sock = new IO::Socket::INET(PeerAddr=>$ip,
PeerPort=>$i,
Proto=>"udp");
# Send the buffer and close the UDP socket.
$sock->send("$buf");
close($sock);

# Wait for incoming packets.
($new_readable) = IO::Select->select($read_set, undef, undef, $icmp_timeout);
# Set the arrival flag.
$icmp_arrived = 0;
# For every socket we had received packets (In our case only one - icmp_socket)
foreach $socket (@$new_readable)
{
# If we have captured an icmp packages, Its probably "destination unreachable"
if ($socket == $icmp_sock)
{
# Set the flag and clean the socket buffers
$icmp_arrived = 1;
$icmp_sock->recv($buffer,50,0);
}
}
if ( $icmp_arrived == 0 )
{
print "Open UDP port : $i\n";
}
}
# Close the icmp sock
close($icmp_sock);
print "End !!\n";


Saturday, January 24, 2009

Perl - simple log-filter script

Lets say we are having a log file in the following format (/var/log/messages format):
Jan 25 00:08:33 localhost kernel: imklog 3.21.9, log source = /proc/kmsg started.
Jan 25 00:08:33 localhost rsyslogd: [origin software="rsyslogd" swVersion="3.21.9" ] restart

Here how to write a simple perl script which will print the log file using a filter (in this sample I will filter the file by its modules : kernel, rsyslogd).

Script start:

#!/usr/bin/perl

# Log file name
$FILE_NAME="messages.txt";

sub read_from_file()
{
# The first (and only) parameter in the module filter string
$MODULE_FILTER=$_[0];

# Open the file for reading, if cannot - exit
open (FHANDLE, "< ${FILE_NAME} ") || die "couldn't open the ${FILE_NAME} file!";

# Reading the file
while ()
{
# Parse the line into its parts using regular expressions
($date,$hostname,$module,$msg) = /^(.+?\s.+?\s.+?\s)(.+?\s)(.+?:\s)(.*)/;
# If ((the filter is not "ANY") and ( current line do not match the filter, in this sample - ignore case)) skip current line
unless (( ${MODULE_FILTER} eq "ANY" ) || ( ${module} =~ /${MODULE_FILTER}/i ))
{
next;
}
# print current line
print $_;
}
# close file handle
close ${FHANDLE}
}

##########################################################
## Main
#&read_from_file("ANY");
#&read_from_file("KERNEL");
Script End;

If I'm calling the subroutine with the "ALL" filter, I will see all the file.
If I will call with the "KERNEL" filter, I will only see the first line.