Search this site

[prev]  Page 2 of 2





pimp, lame, ssh, and streaming!

So since pimp has a cheap shoutcast server thing, I decided to use that to play music while I'm at home.

Playing normal mp3s uses too much bandwidth to waste on my DSL connection (~20-30k/s with 128-160kbit mp3s). So, I decided to use lame as a middleman to down-encode the shoutcasted output from pimp. The following is a little script that uses netcat to connect to the shoutcasty thing aswell as act as a server elsewhere for the down-encoded mp3 data to be sent off.


foo() {
	killall nc
	exit 1

trap foo int 
nc -lp 8081 |&

echo "ICY 200 OK" >&p
echo >&p

nc whack 8080 | lame --mp3input -b 64 - - >&p

I probably don't need to use co-processes, but they're fun, so whatever. Run this script then run mplayer against whatever machine it's on. So what I do is, run the script, then mplayer:

whack(~) > ./projects/pimp/pimp &
whack(~) > ./mp3foo
... over on my laptop ...
nightfall(~) > mplayer http://whack:8081

Poof! Instant mp3 shenanigans. Instead of averaging 24K/s I average 7.5K/s while playing streamed mp3s - what's better is I can still control what song is being played throug pimp's telnet interface and I don't have to waste time downloading every individual song I want to listen to.

Furthermore, here's a nice oneliner to do inbound(download) bandwidth monitoring:

netstat -w 1 | perl -e 'while (<>) { next unless m/^\s+\S+\s+\S+\s+(\d+)/; \
	$b++; $a += $1; print "Total/Avg/Cur = $a / " . ($a / $b) . " / $1\n"; }'

dhclient and dhclient-exit-hooks

Using DHCP on resnet only gives me search as far as search domains. So, I got bored and wrote a small script to add useful domains for me. This is done using a feature of ISC's dhcp program, dhclient, called dhclient-exit-hooks. This is a shell script that is run when dhclient finishes fetching you an IP address.
This will add and to the search line in my /etc/resolv.conf.
Requires: a version of sed that supports inline editing (the -i option)



for dom in $DOMAINS; do
        grep "^search.*\b$dom\b" /etc/resolv.conf > /dev/null 2>&1 || 
        sed -i -e "/^search/ s/$/ $dom/" /etc/resolv.conf