Quick Scanner (Host/Port)

Posted by root Sun, 28 Sep 2008 19:09:00 GMT

#!/usr/bin/ruby

host_port = ARGV[0]
host = host_port.split(':').first
port = host_port.split(':').last

puts %x[nmap -p #{port} #{host}]
Or just:
#!/usr/bin/ruby

host, port = ARGV[0].split(':')

puts %x[nmap -p #{port} #{host}]
Usage (cli and given that the script is named scan_proxy):
./scan_proxy 202.105.182.87:808

Posted in ,  | Tags  | no comments | no trackbacks

Simple Phonebook Script

Posted by root Sat, 20 Sep 2008 14:39:00 GMT


#!/usr/bin/env ruby

class Hash
  def search(arg)
    self.select { |k,v| k =~ /#{arg}/ or v =~ /#{arg}/ }
  end
end

search = ARGV[0]
search =~ /^[0-9]+/ and search = search.to_i

phones = {
  "me"        => "359880101020406",
  "Hitler"     => "+49 666",
  "Van Gog" => "+31",
  "devil"      => "666",
  "God"       => "1",
}

phones.search(search).each do |person|
  print "person:#{person.first}\tnumber:#{person.last}\n"
end

Posted in ,  | no comments | no trackbacks

Remove All Empty Directories

Posted by root Mon, 04 Aug 2008 08:41:00 GMT

alias _rmdir_empty='rmdir * 2>/dev/null'

Posted in  | Tags  | no comments

Converting Between Numeric Bases

Posted by root Fri, 01 Aug 2008 05:58:00 GMT

Sample .bashrc file:
# decimal to binary
alias d2b='ruby -e "puts ARGV.first.to_i.to_s(2)"'
# decimal to hexademical
alias d2h='ruby -e "puts ARGV.first.to_i.to_s(16)"'
# decimal to octal
alias d2o='ruby -e "puts ARGV.first.to_i.to_s(8)"'

# binary to decimal
alias b2d='ruby -e "puts eval(%q|0b| + ARGV.first)"'
# binary to hexademical
alias b2h='ruby -e "puts eval(%q|0b| + ARGV.first).to_s(16)"'
# binary to octal
alias b2o='ruby -e "puts eval(%q|0b| + ARGV.first).to_s(8)"'

# hexademical to decimal
alias h2d='ruby -e "puts eval(%q|0x| + ARGV.first)"'
# hexademical to binary
alias h2b='ruby -e "puts eval(%q|0x| + ARGV.first).to_s(2)"'
# hexademical to octal
alias h2o='ruby -e "puts eval(%q|0x| + ARGV.first).to_s(8)"'

# octal to decimal
alias o2d='ruby -e "puts eval(%q|0o| + ARGV.first)"'
# octal to binary
alias o2b='ruby -e "puts eval(%q|0o| + ARGV.first).to_s(2)"'
# octal to hexademical
alias o2h='ruby -e "puts eval(%q|0o| + ARGV.first).to_s(16)"'

Posted in ,  | Tags  | no comments | no trackbacks

Dracula (The Vampire King)

Posted by root Sat, 26 Jul 2008 21:46:00 GMT

Posted in  | Tags  | no comments

Bulgarian-English command line tool (using sa.dir.bg)

Posted by root Sat, 19 Jul 2008 21:59:00 GMT

#!/usr/bin/env ruby

require 'tempfile'
require 'net/http'

arg =  ARGV[0].chomp
url = 'sa.dir.bg'
h   = Net::HTTP.new(url, 80)

resp,data = h.get("/cgi/sabig.cgi?word=#{arg}", nil )
outtmp    = Tempfile.new("translator")

outtmp << data.to_s
outtmp.rewind
puts %x[html2text "#{outtmp.path}"]

__END__

Posted in  | Tags  | no comments

TRAC - change SVN repository

Posted by root Tue, 08 Jul 2008 00:26:00 GMT

Go to your TRAC project dir and issue the following commands:
1. cd to_your_trac_project_dir
2. ruby -i -pe ’$_.sub! /(repository_dir\s=\s).+/, “repository_dir = NEW_repository_PATH”’ trac.ini
3. trac-admin . resync

Posted in  | Tags  | no comments

mkdir && cd to it

Posted by root Mon, 16 Jun 2008 12:49:00 GMT

# negative - spawning a new shell
mkdir -p $1 && cd $1 && $SHELL

Posted in  | Tags  | no comments

Ruby system administration scripts

Posted by root Sat, 22 Mar 2008 18:45:00 GMT

OS users:
users = File.new("/etc/passwd").collect{|x| x.split(':')[0]}
Number of files in directory:
puts %x{ls}.split(/\n/).size
puts %x[ls|wc].split(/\s+/)[1]
Network interfaces:
inet = Hash.new{|h,k| h[k.split(/\s/)[0]] = k.scan(/addr:(\d+\.\d+\.\d+\.\d+)/)[0].to_s}

%x[ifconfig].to_s.split("\n\n").collect{|x| inet[x]}

# dump the structure: puts inet.inspect

to be continued….

Posted in ,  | Tags  | no comments

How to find free domain name

Posted by root Fri, 22 Feb 2008 21:23:00 GMT

#!/usr/bin/perl

use strict;
use warnings;

my $dom = shift || die "missing name\n";
my $res = qx{whois $dom};

die $1 . "for '$dom'\n" if $res =~ /(no\s+whois\s+server\s+)/i;
die "$dom is free\n"    if $res =~ /no\s+match|does\s+not\s+exist/i;
die "$dom is reserved\n";

__END__
_whois 123456.com
123456.com is reserved

_whois _123456_.com
_123456_.com is free

Posted in ,  | Tags  | no comments

Older posts: 1 2 3