Fun with Google geolocation
posted 2010-08-11 23:23:55, link to this article
After seeing Samy Kamkars talk at DEFCON 18, I really wanted to play with Google's geolocation API.
Some results already:
hessch@turing:~$ bin/mac_geoloc 00:11:92:a1:b2:40
{
"location" : {
"latitude" : 36.1344023,
"longitude" : -115.1620542,
"address" : {
"country" : "United States",
"country_code" : "US",
"region" : "Nevada",
"county" : "Clark",
"city" : "Las Vegas",
"street" : "Las Vegas Blvd S",
"street_number" : "2955",
"postal_code" : "89109"
},
"accuracy" : 150.0}
}
Which is the location one of the hotspot access-points in the Riviera hotel, according to Google. Yay! :)
Bash function to canonicalize MAC addresses
posted 2010-08-11 19:36:02, link to this article
I was playing with some network related stuff this evening and needed to rewrite MAC addresses to the canonical form. That is, something like this 00-02-DE-AD-BE-EF.
Why, you ask? Well every piece of software seems to have their own ideas on how to represent these magical 48 bit integers.
For instance, you'll often see something like 01:02:03:C0:FF:EE, which might also be written in shorthand as 1:2:3:c0:ff:ee or as a (pretty Cisco specific) perversion like 0102.03c0:ffee.
Indeed, a lot of variation...which makes parsing, a bit hellish.
Well I had written a pretty elegant parser in Perl before, that thing groks almost anything that you can
throw at it.
But today I wanted to implement this in hesschlib, hesschlib is my private library of practical
Bash functions. One of the rules of hesschlib is that things should be done in Bash whenever possible.
So I kludged up a small Bash function that does a pretty good job in rewriting most forms of MAC
addresses that came to mind to the canonical form. Here it is:
# canonicalize MAC addresses (does grok most forms)
function maccanon {
canon=''; for octet in ${1//[\.:-]/ }; do
[ ${#octet} -eq 4 ] && octet="${octet:0:2} ${octet:2:2}" ;
[ ${#octet} -eq 1 ] && octet="0${octet}"; canon=${canon}${canon:+ }${octet};
done; echo ${canon// /-};
}
Which is a one-liner in hesschlib, of course, but broken up a bit here to make it more legible.
And finally, here's an example of maccanon in action:
hessch@turing:~$ for mac in 00:02:DE:AD:BE:EF 1:2:3:c0:ff:ee 0102.03c0:ffee
> do
> maccanon ${mac}
> done
00-02-DE-AD-BE-EF
01-02-03-c0-ff-ee
01-02-03-c0-ff-ee
Fix for Thinkpad T400 WWAN on Ubuntu 9.10
posted 2010-02-25 19:51:08, link to this article
The builtin WWAN modem of Lenovo ThinkPad T400 laptops does not seem to wake properly when the laptop is suspended on Ubuntu.
I have written a small Power Manager script to fix this problem, it seems that Ubuntu 9.10 (Karmic Koala) does not support wakeup scripts in /etc/acpi/resume.d anymore.
Although it tires me a bit how much Ubuntu seems to break in new releases lately, it was worthwhile to search for the mechanism "du jour".
It seems that scripts need to be placed in /etc/pm/sleep.d nowadays.
Add the script below to a new file, /etc/pm/sleep.d/10_thinkpad_wwan, and it should be called upon suspend and resume to revive your modem on resume.
#!/bin/sh
# Action script to reinitialize built-in WWAN of Lenovo ThinkPads
# on resume
#
# Hessel Schut, hessel@isquared.nl, 2010-02-25
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
case "${1}" in
hibernate)
# unload cdc_wdm module
rmmod cdc_wdm
;;
resume|thaw)
# revive RF and reload cdc_wdm module
echo 1 > /sys/devices/platform/thinkpad_acpi/rfkill/rfkill1/state
modprobe cdc_wdm
;;
esac
Progress bars in Bash
posted 2009-08-10 07:20:31, link to this article
Today a colleague reminded me to dig up a script that I wrote some years ago to generate progress bars (or actually generic horizontal bar graphs) in Bash.
The script is, in this state, more like a proof of concept. It displays an bar that increments until full and then decrements again, this cycle is repeated forever. It should not be too hard to rewrite it to be used in something more useful.
I think it's also trivial to rewrite this to display vertical bar graphs as well. I might write a small Bash library to include in other scripts later, if and when I feel the need to. ;-)
The code of the script follows below, enjoy...
#!/bin/bash
# progress bar
# Hessel Schut, VPRO Automatisering, 2004-04-02
cols=$(tput cols)
bold=$(tput smso)
norm=$(tput rmso)
trap cleanup EXIT TERM INT
cleanup() {
norm
tput clear
tput cnorm
exit
}
hor_line() {
for ((i=1; i < cols - 2; i++)); do
echo -n '-'
done
}
draw_frame() {
tput cup 2 2; hor_line
tput cup 3 1; echo -n '|'
tput cup 3 ${cols}; echo -n '|'
tput cup 4 2; hor_line
}
tput clear
tput civis
draw_frame
d=1; pos=2; plen=0
while [ == ]; do
[ $d -eq 1 ] && face=${bold}
tput cup 3 $pos
echo -n ${face}' '
face=${norm}
sts='pos: '${pos}' dir: '${d}
tput cup 1 1; echo -n ${norm}${sts}
[ ${plen} -gt ${#sts} ] && for ((i=0; i < plen - ${#sts}; i++)); do
echo -n ' '
done
plen=${#sts}
((pos += d))
[ $pos -gt 2 ] && [ $pos -lt $((cols - 2 )) ] || ((d=-d))
done
Cobalt status LCD, NetBSD version
posted 2008-11-09 00:18:41, link to this article
Here is a NetBSD/Cobalt version of my Cobalt Qube/Raq LCD status screen updater.The Debian linux version is described in an earlier post on this page, here: Cobalt Qube status LCD system monitor. This script works fine on NetBSD/Cobalt 3.0, I haven't tested it on other versions yet. You can download the new NetBSD version at http://isquared.nl/src/lcdbanner-netbsd.sh
Cobalt Qube status LCD system monitor
posted 2008-11-01 21:58:29,
link to this article
Read full article
This is a handy framework to monitor several system parameters on Cobalt hardware running Debian GNU/Linux.
Bourne/ Bash Shell CGI Scripts
posted 2008-11-01 21:49:09,
link to this article
Read full article
Usually I do my server-side scripting in Perl, but some time ago when writing CGI scripts for an embedded system I ran into memory and flash space contraints. Because the system used Busybox, I had the Bourne compatible ash shell available.
So I wrote a very small Bourne shell script to include in my CGI scripts, which I share here, maybe it is of use to someone.
isquared.nl rss (atom)