Visualizzazione post con etichetta Perl. Mostra tutti i post
Visualizzazione post con etichetta Perl. Mostra tutti i post

giovedì 9 maggio 2013

How To Identify If a Port Is Listening on a Unix Server



Hi all

To see if a port is listening on a Unix Server command is :

           netstat -an | grep port number | grep LISTEN

To see what process is using a port the command is :

           lsof -i tcp:port number

Here a simple perl programm to open a port and check a connection from a client web :


#!/usr/bin/perl -w
        use IO::Socket;
        use Net::hostent;              # for OO version of gethostbyaddr
        $PORT = 8080;

        $server = IO::Socket::INET->new( Proto     => 'tcp',
                                         LocalPort => $PORT,
                                         Listen    => 5,
                                         Reuse     => 1) or die "can't setup server" unless $server;

    printf("\nSERVER Waiting for client connection on port $PORT");

         while ($client = $server->accept()) {

          printf("\nClient Connected\n");

          $client->autoflush(1);
          print $client " Connected You are connected on port $PORT";

          close $client;
        }

Stay tuned


lunedì 4 giugno 2012

giovedì 27 maggio 2010

Script PERL : Totals File in a Directory

This is a simple script to show total number of Files in a directory.

Script accepts in input one argument : Directory.


$totfile = 0;
opendir(my $dh, $ARGV[0]) || die;
while(readdir $dh) {
print "$some_dir/$_\n";
$totfile++;
}
closedir $dh;

printf(" Tot Files : $totfile \n");

Stay Connected.

lunedì 24 maggio 2010

Stat command in Perl (Unix/Linux)

This perl script execute a stat of a file in UNIX/LINUX environment and accept in input file name with absolute path. It shows various file info and atime, mtime and ctime.

#!/usr/bin/perl -w

#
# stat.pl
#

($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($ARGV[0]);

print("dev = $dev\n");
print("ino = $ino\n");
print("mode = $mode\n");
print("nlink = $nlink\n");
print("uid = $uid\n");
print("gid = $gid\n");
print("rdev = $rdev\n");
print("size = $size\n");
print("atime = $atime\n");
print("mtime = $mtime\n");
print("ctime = $ctime\n");
print("blksize = $blksize\n");
print("blocks = $blocks\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($ctime);
$year = $year + 1900;
$month = $month + 1;
printf(" ctime $year/$month/$day $hr:$min:$sec\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($mtime);
$year = $year + 1900;
$month = $month + 1;
printf(" mtime $year/$month/$day $hr:$min:$sec\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($atime);
$year = $year + 1900;
$month = $month + 1;
printf(" atime $year/$month/$day $hr:$min:$sec\n");

Stay connected.


venerdì 23 aprile 2010

Perl : Programming Documentation Site

For some scripts in my work on HP Unix Pa-Risc/Itanium I’m using PERL.
It’s a very good scripting language and I have found this site to help me in script creation:

Site : http://perldoc.perl.org/index-functions.html

I recommend this site, it’s a very good resource and help for Perl programming.

To the next Post.

Check Mid Year Objectives

Hi all Today middle year check of my 2026's goals. 1. ENGLISH Improve listening comprehension (So and So)   See at least one or two film...