Looking into IO::Socket at http://search.cpan.org/src/GBARR/IO-1.2301/IO/Socket.pm reveals: [perl] sub send { @_ >= 2 && @_ <= 4 or croak ‘usage: $sock->send(BUF, [FLAGS, [TO]] +)’; my $sock = $_[0]; my $flags = $_[2] || 0; my $peer = $_[3] || $sock->peername; croak ‘send: Cannot determine peer address’ unless($peer); [/perl] So you have to take care that […]
Perl – Is a value decimal, real or a string? To validate if a number is a number using regex. [perl] $number = “12.3”; if ($number =~ /\D/) { print “has nondigits\n” } if ($number =~ /^\d+$/) { print “is a whole number\n” } if ($number =~ /^-?\d+$/) { print “is an integer\n” } if […]
#!/usr/local/bin/perl use strict; use warnings; print “Starting main program\n”; my @childs; for ( my $count = 1; $count <= 10; $count++) { my $pid = fork(); if ($pid) { # parent #print “pid is $pid, parent $$\n”; push(@childs, $pid); } elsif ($pid == 0) { # child sub1($count); exit 0; } else […]
<? print “Starting main program\n”; $childs = array(); for ( $count = 1; $count <= 10; $count++) { $pid = pcntl_fork(); if ( $pid == -1 ) { // Fork failed echo “Fork failed\n”; exit(1); } else if ( $pid ) { # parent #print “pid is $pid, parent $$\n”; array_push($childs, $pid); } […]
Mr. Peabody Explains fork() Introduction How Windows Does It How Unix Does It So Why Do People Want the Unix Way? How does it work in Perl? Introduction UNIX – Fork Explained Say, Mr Peabody. I was just reading through the Perl 5.6 release notes and noticed that a new function called fork() is now […]
Ubuntu – What package does a file belong to?? apt-file search filename or apt-file search /path/to/file To install apt-file, use: sudo apt-get install apt-file You will need to update its database before you can use it: sudo apt-file update
Ubuntu – Which Process is Using a port? 1- Find what application/process is using the pro, type: sudo netstat -lpn |grep :8080 and press Enter. You will get an output similar to this one tcp6 0 0 :::8080 :::* LISTEN 6782/java 2- I have got the process Id, which is 6782, now this is the […]
Heart Bleed – Exploit Example Code If you need to test your server for the vulnerability, here is a simple Python script… [python] #!/usr/bin/python import sys import struct import socket import time import select import re from optparse import OptionParser options = OptionParser(usage=’%prog server [options]’, description=’Test for SSL heartbeat vulnerability (CVE-2014-0160)’) options.add_option(‘-p’, ‘–port’, type=’int’, default=443, […]
In case you haven’t heard, a critical bug in the widely used OpenSSL library has been disclosed this week. http://www.bbc.co.uk/news/technology-26971363 Despite the cool name and vector logo, Heartbleed is one of the scariest security bugs to hit the Internet in a long time. I was able to query my own server to reveal memory […]
Perl – Compare Array Contents when length is identical and order matches Comparing arrays side by side. Do they match or dont they? @a=(1,0,1,0,0); @b=(0,0,1,0,0); NO! @arr1=(0,1,1,1,1,1,0,1); @arr2=(0,1,1,1,1,1,0,1); use Algorithm::Diff qw( LCS_length); my $arr_count1 = @arr1; my $arr_count2 = @arr2; if($arr_count1 != $arr_count2) { print “NOMATCH\n”; ## NO MATCH } else { $count = LCS_length […]