Saturday, May 31, 2008

AC3 demystified for AppleTV (Fsck You Apple !!)

Anywayz, it just didn't have to be this complicated. "Apple" could easily make this box do a lot more than what it does now without keeping this superb-lame intention of leaving this box half crippled and restricted.

Back to the point ...

[»] AC3 works only through optical output, should also work through hdmi, but I have not tested it myself since I have only 1 hdmi cable at home.

[»] change the following keys in apple.tv by logging in as frontrow :

(1) defaults write com.cod3r.a52codec attemptPassthrough 1

if you have ATV-files installed ::
(2) defaults write net.ericiii.ATVFiles EnableAC3Passthrough 1

if you have nitoTV installed ::
(3)
defaults write com.apple.frontrow.appliance.nitoTV passthru 1


[»] nitoTV automatically installs ffmpeg at this location :: /System/Library/CoreServices/Finder.app/Contents/PlugIns/nitoTV.frappliance/Contents/Resources/ffmpeg

[»] to check if a video has ac3 :: ffmpeg -i video.avi ... it will print the audio/video informations for the input video.

[»] after changing the keys, restart frontrow or reboot appleTV and play the video with AC3, it should give you 5.1 sound output now.

Fsck you Apple, for making it so complicated, if I knew it before, I would have just bought a cheap media-center pc and would happily run mythTV on it. FSCK you again ... Either make a proper iTunes for linux or leave the damn thing out of the way, so that I can store and play my files on the device without any intervention of the fscking itunes ...

[ sorry guys, just couldn't stop myself. I kind of spent the whole last night digging into this ac3 problem, went to bed at 7am in the morning. now you tell me, who would know those correct key names to change, if you dont digg this much ... sorry once again for not being able to control my rage on Apple for making so unnecessarily complicated ]

Fuzzy check if a bash input is string or a number

Couldn't think of anything better. Please leave comments if anything better exists.

#!/bin/bash
read -p "[*] input" in

if [ $((in+1)) -eq 1 ]
then
 echo "input is a STRING"
else
 echo "input is a number"
fi


Friday, May 30, 2008

send sms from shell !!! [pennytel]


source code for my "sms.sh" with some bells and whistles ... ;-)

#!/bin/bash

db='/home/babil/scripts/sms.db'

### input password
echo
read -s -p "[*] enter password: " pass 
echo
###


### input recipient
echo
recp_no=''

while [ -z "$recp_no" ]
do
 read -p "[*] enter recipient: " recp_in
 
 if [ $((recp_in+1)) -eq 1 ]
 then
  s=''
  s=`cat $db | grep -w $recp_in`

  if [ ! -z "$s" ]
  then
   recp_name=`cat $db | grep -w $recp_in | awk '{print $1}'`
   recp_no=`cat $db | grep -w $recp_in | awk '{print $2}'`
   echo "[*] recipient number found : $recp_no"
  else
   recp_no=''
  fi
 else
  
  recp_no=$recp_in

  s=''
  s=`cat $db | grep -w $recp_in`
  if [ -z "$s" ]
  then
   read -p "[*] give recipient a name : " recp_name
   echo "$recp_name $recp_no" >> $db
   
  else
   recp_no=`cat $db | grep -w $recp_in | awk '{print $2}'`
   recp_name=`cat $db | grep -w $recp_in | awk '{print $1}'`
  fi
 fi
done
###



### input sender
echo
sender_in=''
read -p "[*] enter sender: " sender_in

if [ $((sender_in+1)) -eq 1 ]
then
 s=''
 s=`cat $db | grep -w $sender_in 2>/dev/null`

 if [ ! -z "$s" ]
 then
  sender_no=`cat $db | grep -w $sender_in | awk '{print $2}'`
  sender_name=`cat $db | grep -w $sender_in | awk '{print $1}'`
  echo "[*] sender number found : $sender_no"
 else
  sender_no=''
 fi
fi

if [ -z "$sender_no" ]
then
 echo "[*] using default sender : 614XXXXXXXX"
 sender_name='default'
 sender_no='614XXXXXXXX'
fi
###


### input message
rem=0
while [ $rem -le 0 ]
do
 echo
 read -p "[*] enter message: " msg
 msg=`echo $msg | sed -e 's/ /\+/g'`

 len=${#msg}
 rem=$((157-len))
 if [ $len -ge 157 ]
 then
  echo -n "[$len/$rem]"
 fi
done
###



### print info
echo
echo "[>] recipient  : $recp_name $recp_no"
echo "[>] sender     : $sender_name $sender_no"
echo "[>] message    : $msg"
echo "[>] length     : $len / $rem"
echo
###


### confirm with user
read -n1 -p '[?] are you happy with the setting : [y/n]  ' yn
echo

if [ "$yn" != "y" ] || [ ! "$yn" != "Y" ]
then
 exit 1
fi
###


### send message
echo
echo '[*] Trying to send ...'
echo

curl -c cookie.txt -d "username=6128XXXXXXX&password=$pass" "https://www.pennytel.com/m/login.jsp" -L 2>&1 1> /dev/null 
 
m=`curl -b cookie.txt -d "trans=SendSMS&pagecaller=SMS&smstype=Premium&recipient=$recp_no&smscount=1&message=$msg&counter=$rem&mobilenumber=%2B$sender_no&credit=%24+4.31&freesms=0&walalang=FREE" "https://www.pennytel.com/sms_sent.jsp" -L -A='Mozilla/5.0' -e='http://www.pennytel.com/m/index.jsp?error=Invalid%20Entry' -# 2>/dev/null | grep "Please enter your username and password"`
 
echo
if [ -z $m ]
then
 echo '[*] SUCCESS.'
else
 echo '[*] FAILED.'
fi
 
rm cookie.txt 2>/dev/null
echo
###

Wednesday, May 14, 2008

DCCP-CCID4 bug+patch (p1)


if (hctx->p > 0)
// when loss
{
hctx->x = min(((u64)hctx->x_calc) << 6, min_rate);
low_thresh /= TFRC_T_MBI;
ccid4_hc_tx_x_header_penalty(hctx);
}

else if (ktime_us_delta(now, hctx->t_ld) - (s64)hctx->rtt >= 0)
// no-loss
{
hctx->x = min(2 * old_x, min_rate);
low_thresh = scaled_div(low_thresh, hctx->rtt);
hctx->t_ld = now;
/*ccid4_hc_tx_x_header_penalty(hctx);*/

// babil
// header penalty should not be applied if there's no loss yet
// it will effectively stop the X from growing higher in a small packet and
// low data-rate stream, while the available bandwidth is higher on the link.
}



Thursday, May 8, 2008

calculate Jitter from a pcap file

#!/bin/bash

if [ -z $1 ]
then
 echo "[+] $0 capture.pcap"
 exit
fi

if [ ! -z $2 ]
then
 limit=$2
else
 limit=0
fi

#tshark -r $1 | grep "1.1.1.1 -> 1.1.1.2" | grep -v "ICMP"| grep -i "\[Data\] Seq\|UDP\|TCP" | awk '{if(NR==1){f=$2;s=$2};print ($2-f),($2-s)*1000;s=$2;}' > jitter.tmp
tshark -r $1 | grep "1.1.1.1 -> 1.1.1.2" | grep -v "ICMP"| grep -i "\[Data\|UDP\|TCP" | awk '{if(NR==1){f=$2;s=$2};print ($2-f),($2-s)*1000;s=$2;}' > jitter.tmp

#cat jitter.tmp | awk '{ k=$2-s ; if(($2-s)<0){k=($2-s)*(-1)} ; t=t+k ; print $1,$2-s,t/NR ; s=$2}' > jitter.txt ## mixed
cat jitter.tmp | awk -v l=$limit '{ k=$2-s ; if(($2-s)<0){k=($2-s)*(-1)} ; t=t+k ; if(k>l){print $1,k,t/NR}; s=$2}' > jitter.txt ## all positive

avg=`tail -n1 jitter.txt | awk '{print $3}'`

echo 'set data style points' > jitter.gp
echo 'set nogrid' >> jitter.gp

echo 'set style line 1 lt 1 lw 2' >> jitter.gp
echo 'set style line 2 lt 2 lw 2' >> jitter.gp
echo 'set style line 3 lt 3 lw 5' >> jitter.gp
echo 'set style line 4 lt 3 lw 1' >> jitter.gp
echo 'set style line 5 lt 3 lw 2' >> jitter.gp
echo 'set style line 6 lt 3 lw 1' >> jitter.gp
echo 'set style line 7 lt 17 lw 2' >> jitter.gp
echo 'set style line 8 lt 17 lw 4' >> jitter.gp

echo '#set logscale y' >> jitter.gp
echo '#set xrange[1:180]' >> jitter.gp
echo '#set yrange[1:2]' >> jitter.gp
echo '#set samples 2000' >> jitter.gp
echo '#set xtics 50' >> jitter.gp
echo '#set ytics 50' >> jitter.gp

echo 'set xlabel  "Time (sec)"' >> jitter.gp
echo 'set ylabel  "Kbit/s"' >> jitter.gp

echo 'plot "jitter.txt" using 1:($2/1) title "jitter ('$avg'ms)" with impulses ls 6' >> jitter.gp
echo '#plot "jitter.txt" using 1:($2/1) title "jitter ('$avg'ms)" with lines ls 6' >> jitter.gp
echo '#replot "jitter.txt" using 1:($3/1) title "cumul jitter ('$avg'ms)" with lines ls 8' >> jitter.gp

echo 'set encoding iso_8859_1' >> jitter.gp
echo 'set term post color "Helvetica" 18' >> jitter.gp
echo 'set output "jitter.eps"' >> jitter.gp
echo 'replot' >> jitter.gp

echo 'set term png' >> jitter.gp
echo 'set output "jitter.png"' >> jitter.gp
echo 'replot' >> jitter.gp

gnuplot jitter.gp 2>&1 1>/dev/null
qiv jitter.png &

My kick-ass script to compute min,max,avg & standard deviation ;)


#!/bin/bash

function usage()
{
echo
echo "[*] usage: $0 filename column"
echo
exit
}

if [ -z $1 ] || [ -z $2 ]
then
usage
fi

line=`cat $1 | wc -l`
max=`cat $1 | awk -v c=$2 '{if($c>=s){s=$c;line=NR}}END{print s,"("line")"}'`
min=`cat $1 | awk -v s=9999999999 -v c=$2 '{if($c<=s){s=$c;line=NR};}END{print s,"("line")"}'`
avg=`cat $1 | awk -v c=$2 '{total=total+$c}END{print total/NR}'`
stdev=`cat $1 | awk -v avg=$avg '{x=$1-avg;total=total+x*x;}END{print sqrt(total/NR)}'`

echo
echo "[*] input : $1"
echo "[*] column : $2"
echo "[*] no of data : $line"

echo
echo "[*] min : $min"
echo "[*] max : $max"
echo "[*] std.dev : $stdev"
echo


Monday, May 5, 2008

Hang on Lois, Super man is coming !!!


www.sfgate.com

aha, so this is how superman provides his service in Mexico !!!


Saturday, May 3, 2008

Sharp fonts in firefox [K/Ubuntu]


apt-get install msttcorefonts
Download this file :: http://www.sharpfonts.com/fontconfig.tbz
sudo tar xjvf /etc/fonts

restart firefox ... open www.google.com ... you'll see the difference for yourself ;)


My firefox fonts settings :

  • Default font :: Verdana :: Size=12
  • Font for :: Western
  • Proportional :: Serif :: Size = 12
  • Serif :: Verdana
  • Sans-Serif :: Verdana
  • Monospace :: Terminux :: Size = 12
  • Minimum Font Size :: 12

  • Allow pages to chose their own fonts
  • Default character encoding :: Western (windows-1252)


Thursday, May 1, 2008

Finding out Kubuntu version

lsb_release -a