Archive

Archive for the ‘Uncategorized’ Category

Dummy Image Viewer (DiV) – I don’t like WPF very much but…

…I needed a lightweight image viewer to quick scan thousands snapshots coming from the Ladle Tracking system (steelworks) I work on. Unfortunately (IMHO :)) the main company I’m working for at the moment, uses MS WPF (Windows Presentation Foundation) as platform for its software. Therefore, in the last year I’ve had to learn a bit of C# , WPF, MVVM pattern and so on, and it was the easiest method to get a small program quickly.

In two days of work this small size, standalone and quite dummy viewer has born. The main feature is the possibility to watch the current snapshot, 4 “previous” snapshots (at -8, -16, -32, -64) and 4 “following” (at +8, + 16, +32, +64) and skip (+/- 32 but configurable) forward/backward with Down/Up arrow keys. A bit of zoom stuff, some settings and finally I can avoid loosing time watching file previews in a painfully slow VPN!

It’s a really raw small program but maybe someone can find it useful and help to improve. I’ve load it on GitHub:

DiV on GitHub

Press H for a quick help and have fun!

 

Download Dummy Image Viewer

 

DiV snapshot

What’s your (my) (external) IP address?

Until IPv6 will have conquered the world (and maybe neither that time) DSL will continue to operate with dynamic IP address. I have the usual home server behind my home router and sometimes I need to access remotely. What’s my home router’s external IP?

Until now I used a script in my server that uploads via ftp the ip on this site, an easy supybot plugin I wrote to ask my IRC bot the IP, or used one of my remote access plugins and I stopped sending the IP via mail (too much fighting with Gmail spam filters).

My friend Riccardo Catto had the same problem and asked me to write together a simple plugin that fetchs the external IP from one of the many sites that provide that kind of service. A bit of libpurle magic and we came out with this ‘What’s my IP’ plugin. I use it with finch in my home server and every time I need to know my external IP I just write ‘ip’ in a chat with finch buddy and it answer with something like:

Current IP Address: X.X.X.X

…and I kiss the monitor to thanks it.

Easy but somewhat useful :)

Port Forwarding via Instant Messaging

Another plugin thet exploits Instant Messaging to transfer data. This time I’ve implemented a port forwarding using NetCat that do all socket stuffs. The plugin simply encode and transfer data from local pidgin to the buddy’s pidgin. There another ncat instance connect to the host we want to reach. The bandwidth is… ehm… quite low (1 KB/s with default settings) but sometimes it’s useful to pass through NATs, firewalls, …

It’s very basic and the next step should be to implement a real socket server that accepts multiple connections keeping them distinct (At the moment you can tell ncat to accept several clients but the traffic is mixed up).

Instant messaging Port Forwarding



If you have time to waste take a look!

Quick and Dirty bash script to check bandwidth usage

I need it to shutdown my home server when it’s idle for a long time. Nothing very elegant, a bit of grep on ifconfig output but it seems to work fine. Have fun!

Donwload bwusage


#! /bin/bash

# BandWidth Usage
# Federico Zanco

IFACE=eth0
TIMEOUT=10
RX="1"
TX="1"
TRAFFIC="FALSE"
UNIT="KiB"
VERBOSE=

show_help () {
echo
echo "usage: bwusage [-h|--help] [-i|--interface ] [--rx-only]"
echo " [--tx-only] [--traffic] [-t|--timeout ]"
echo " [-u|--unit [-v|--verbose]"
echo
}

change_unit () {
case "$UNIT" in

"KiB")
[ "$1" = "RX" ] && RX=`echo "$RX"|awk '{printf "%0.4f", $1 / 1024}'`
[ "$1" = "TX" ] && TX=`echo "$TX"|awk '{printf "%0.4f", $1 / 1024}'`
;;

"MiB")
[ "$1" = "RX" ] && RX=`echo "$RX"|awk '{printf "%0.4f", $1 / 1048576}'`
[ "$1" = "TX" ] && TX=`echo "$TX"|awk '{printf "%0.4f", $1 / 1048576}'`
;;

esac
}

TEMP=`getopt -q -o hi:t:u:v --long help,interface,rx-only,tx-only,traffic,timeout,unit,verbose -- "[email protected]"`

eval set -- "$TEMP"

while true ; do
case "$1" in

-h|--help)
show_help
exit 0
;;

-i|--interface)
IFACE=$2
shift 2
;;

--rx-only)
TX=
shift
;;

--tx-only)
RX=
shift
;;

--traffic)
TRAFFIC="TRUE"
shift
;;

-t|--timeout)
TIMEOUT=$2
shift 2
;;

-u|--unit)
[ "$2" != "B" -a "$2" != "KiB" -a "$2" != "MiB" ] && echo && echo "ERROR: unit $2 not valid" && show_help && exit 1
UNIT=$2
shift 2
;;

-v|--verbose)
VERBOSE="1"
shift
;;

*)
# [ "--" != "$1" ] && echo && echo "ERROR: $1 unknown option" && show_help && exit 1
break
;;
esac
done

[ -z "$(ifconfig -s |grep $IFACE)" ] && echo && echo "ERROR: $IFACE not up or not valid" && exit 1

[ -n "$VERBOSE" ] && echo
[ -n "$VERBOSE" ] && echo "IFACE=$IFACE"
[ -n "$VERBOSE" ] && echo "TIMEOUT=$TIMEOUT s"
[ -n "$VERBOSE" ] && echo "TRAFFIC=$TRAFFIC"
[ -n "$VERBOSE" ] && echo "UNIT=$UNIT"
[ -n "$VERBOSE" ] && echo
[ -n "$VERBOSE" ] && echo "... please wait $TIMEOUT seconds ..."
[ -n "$VERBOSE" ] && echo

[ -n "$RX" ] && rx1=`cat /sys/class/net/$IFACE/statistics/rx_bytes`
[ -n "$TX" ] && tx1=`cat /sys/class/net/$IFACE/statistics/tx_bytes`

sleep $TIMEOUT

[ -n "$RX" ] && rx2=`cat /sys/class/net/$IFACE/statistics/rx_bytes`
[ -n "$TX" ] && tx2=`cat /sys/class/net/$IFACE/statistics/tx_bytes`

if [ -n "$RX" ]
then
RX=`echo "$rx2 - $rx1"|bc`
[ "$TRAFFIC" = "FALSE" ] && RX=`echo "$RX $TIMEOUT"|awk '{printf "%0.4f", $1 / $2 }'`
change_unit "RX"
[ -n "$VERBOSE" ] && echo -n "RX: "
echo "$RX"|awk '{printf "%0.2f", $1 }'
[ -n "$VERBOSE" ] && echo -n " $UNIT" && [ "$TRAFFIC" = "FALSE" ] && echo -n "/s"
fi

[ -n "$RX" ] && [ -n "$TX" ] && echo -n " "

if [ -n "$TX" ]
then
TX=`echo "$tx2 - $tx1"|bc`
[ "$TRAFFIC" = "FALSE" ] && TX=`echo "$TX $TIMEOUT"|awk '{printf "%0.4f", $1 / $2 }'`
change_unit "TX"
[ -n "$VERBOSE" ] && echo -n "TX: "
echo "$TX"| awk '{printf "%0.2f", $1 }'
[ -n "$VERBOSE" ] && echo -n " $UNIT" && [ "$TRAFFIC" = "FALSE" ] && echo -n "/s"
fi

echo

Yet another virtual terminal plugin: Instant messaging Remote Access

imra_screenshot1

imra_screenshot1


Now… I know I’m a bit obsessed by this arguments but I was quite unhappy with ImVT. Having become aware of the work to reach a minimal stable state with ImVT I realized I don’t have enough time. I’d like to write a library that handles only issues terminal related (interpret signals, escape/control sequences, …) allowing you to avoid to use a GUI (Gnome VTE forces you to have a gui for your terminal emulator) and to work with a simplified interface to push input and read processed output in some friendly way (markup? XML/HTML?). I’d like to but… now I can’t (and I don’t know if I were able to!).
So the idea I’ve done this new plugin, less versatile but a little bit more robust and far far away easier to write! The final result is a kind of telnet via IM. If you’re unsatisfied with ImVT take a look to ImRA and please leave a feedback!

Funny ideas (virtual Terminal via IM???)

I think the XMPP protocol can be considered as a sort of middleware allowing to transport any type of data in the network without worrying too much about the nature of the data, the place where data is, and protocols used to transport data from one side to another.

In a certain way this behaviour is quite similar to Sockets that, using a public service (such as a Jabber server), allow you to bypass many of the barriers (NATs, firewalls, …) dividing two hosts on the Internet.

Think about this idea: developing a libpurple plugin acting like netcat or a pipe between two buddies, that you can use to pass ANY kind of data or stream. Something like: right click on buddy and click on “create socket on port 1234” or “create named pipe”.

I know this is a trivial idea and there are plenty of systems that do this. But what can make the difference (IMHO) is that:

  • XMPP is XML based and this allows anyone to define their own protocol
  • a lot of IMs support  XMPP and chat/IMs are very popular and widely used, moreover they are a public services and usually can pass through NATs quite easily (although this should not be a problem with IPv6!)
In the last months I’ve stopped developing  XMPP / Gtalk invisibility plugins[1] to try to implement an “old” idea: create a virtual terminal controlled via IM.

After an initial stage to get a bit of knowledge about (pseudo) terminal emulators (Advanced Unix Programming rocks :)) I’ve given birth to Instant messaging Virtual Terminal (ImVT). It’s now a very buggy prototype, but for “easy” tasks it does its job. I was able to run commands like ssh, vim (with some issues), and some other commands that require a terminal. Forget to run commands that produce constantly output (i.e. top).

Unfortunately I can not spend too much time developing it so, for now, it’s only a small buggy toy.
If anyone more experienced (especially in terminal emulators programming!) thinks that I am not too insane and likes the idea to help to develop… just send me an email!

Please pay attention to security issues: every buddy allowed to chat with the account used by ImVT can gain access to the terminal emulator!!!

  1. [1] I’m looking forward to develop Google Invisibility Tracker enhancement log every buddies’ status change and every presence stanza received, including those sent by iGoogle or Gmail when chat is turned off (that means that buddy was on the Internet). I just have to find time to do it!

a little (and probably short term) hope about detecting invisible buddies in Google Talk

a small variant of the first method to detect invisible buddies in Google Talk.


The first method consisted in starting a chat with the buddy we assumed invisible. If we got the message “[email protected] is offline and can’t receive messages right now.” then the buddy was offline but if didn’t appear any message then we could determine that our buddy was really invisible.


Now this bug has been fixed by Google but…


Let’s try to invite the invisible buddy in a group chat and see what happens…


In Pidgin this is quite easy: right click on the offline (invisible) buddy and click on “Start a chat”. This will start a group chat if the buddy is invisible.


Obviously this bug will have a short life and the method it’s not stealth (and difficult to apply to all buddies but not impossible) but for now…

Google fixed the “bug” to scan invisible buddies

It seems that Google has fixed what we used to consider a bug but was not properly a bug but simply an implementation choice.

From XMPP IM page:

5.1.3. Presence Probes

Upon receiving a presence probe from the user, the contact’s server SHOULD reply as follows:

3. Else, if the contact has no available resources, the server MUST either (1) reply to the presence probe by sending to the user the full XML of the last presence stanza of type “unavailable” received by the server from the contact, or (2) not reply at all.

obviously if we consider invisibility like a offline status we have to accept both cases. Until now we could scan invisible buddies because Google Server used two different behaviors for Offline and Invisible status.

And now?

Now the “half scan method” is no more useful. I don’t know any other method to do the same.

For now the only way I know to have information about invisible buddies is this plugin but it’s neither tested nor reliable and you have to be online when your buddies goes invisible.

Under Construction… ?

Now… installed WordPress to avoid that horrible index page but don’t expect too much from this little revolution. This site will probably be under construction for a looong long time.

Have fun!

Bulldozer