Getting ip addresses from log file

Posted by root Tue, 08 Jan 2008 09:10:00 GMT

perl -ne

$_{$1}=1 if /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;eof&&{print join("\n", sort keys %_)}
access.log

Posted in  | Tags ,  | no comments

Fast ICMP scanner (Perl oneliner)

Posted by root Tue, 08 Jan 2008 08:05:00 GMT

[localhost]$

time perl -MNet::Ping -e '$p = Net::Ping->new();
@hosts = qw(
127.0.0.1 
172.16.0.1 
172.16.0.2 
172.16.0.5 
172.16.0.254);
#the significant detail
$p->{"timeout"} = 0.005; 
for (@hosts) { print "$_ is ".($p->ping($_) ? "up" : "down").$/ }'

127.0.0.1 is up
172.16.0.1 is up
172.16.0.2 is down
172.16.0.5 is up
172.16.0.254 is down

real 0m0.062s
user 0m0.040s
sys 0m0.000s

Posted in  | Tags ,  | no comments

Simple file hiding

Posted by root Tue, 08 Jan 2008 07:45:00 GMT

irb console
$/ = "\r\n"

# addition of .mp3 file to .gif file
File.open('test.gif', 'a') do |fh| 
  fh << "\r\n#{File.readlines('test.mp3')}"
end

# extraction of the .mp3 content
File.open('extracted.mp3', 'w') do |fh| 
  fh << File.readlines('test.gif')[1..-1]
end

Posted in  | Tags  | no comments

Six happy numbers

Posted by root Tue, 08 Jan 2008 06:22:00 GMT

numbers = Hash.new

loop{numbers[rand(50)]=true && numbers.keys.size==6 && break}

p numbers.keys.sort.join(%q/ /)

or just

p (1..49).to_a.sort_by{rand}.[](1..6)

Posted in  | Tags  | no comments

Older posts: 1 2