Tuesday, 25 August 2009

Interact with other local Linux terminal sessions

If you're interested in trying to control/inject/view other terminal sessions (e.g. with ssh or telnet on a tty or pts) that you/someone is logged into on that machine then read on. Handy for zapping that vi session you left running at work, or playing havoc with something random ;)

It seems that watch does the trick for FreeBSD, but for Linux there's only things like ttysnoop (for linux-2.6) but that requires you modify your /etc/inittab files which is a bore. There's also conspy but that only works with physical terminal devices not ptys, as far as the docs say...

However you can do it without altering anything:
  • See what's being typed (and subsequent output) in another terminal session by using peekfd - you just need to supply the UID of the shell running on that other terminal (find it using ps). Watch out as the output may well contain some 8-bits chars which can confuse your current terminal - though you can get it back to normal using a terminal reset. (e.g. sudo peekfd /dev/pts/27)
  • Inject characters into a terminal by using the TIOCSTI ioctl() with this neat Perl script (copied below). Find the tty of the process you're interested in (e.g. ps axg | grep vi) and use that as the argument to the perl script e.g. echo 'ZZ' | sudo ./catvt.pl /dev/pts/27
  • #!/usr/bin/perl -w
    use strict;
    use Fcntl;
    use constant TIOCSTI => 0x5412;
    unless (@ARGV >= 1) {
    print "usage: $0 [vt] <input>\n";
    exit; }
    my $vt = shift @ARGV;
    my $buf = join '', <>;
    &writevt ($vt, $buf) || die "can't write to $vt: $!\n";
    sub writevt {
    my ($vt, $buf) = @_;
    sysopen (VT, $vt, O_RDONLY) || return 0;
    for (my $i = 0; $i < length $buf; $i++) {
    ioctl (VT, TIOCSTI, substr ($buf, $i, 1)) || return 0; }
    close (VT) || return 0;
    return 1; } 
[updated 6jan10]

Monday, 10 August 2009

Panasonic microwave manuals

There seems to be a few annoying websites out there that ask for payment for user manuals - fortunately Panasonic have most of their manuals online for everything from microwaves, cameras, camcorders. There's also a link to their global support site.

Sunday, 2 August 2009

IPv6 Tunnel with Thompson router (from a Time Machine)

[updated 5oct12, 25jul10] I've recently got myself a Thompson router which has a bunch of interesting stuff in it once you get into the telnet access (the username/password used depends on your provider e.g. Plusnet (Administrator/your_router_serial_num), O2 (SuperUser/O2Br0ad64nd OR your_router_serial_num), etc). To get a tunnel working for Hurricane Electric, Sixxs, you need to [temporarily] allow IPv4 pinging of your box. Once you enable it at tunnel setup time - so here's how to do it.
%telnet your_router
{Administrator}=>:service system ifadd name=PING_RESPONDER group=wan

Once you've set it up on the website then you can disable it again:
{Administrator}=>:service system ifdelete name=PING_RESPONDER group=wan

On some systems you may need to allow 6to4 IPv6 tunnelling through the NAT - just try the above first and see if the tunnel works. If it doesn't then you could look here for info enabling it. [Update18jul10]: To enable it telnet to your Thompson box and type the following - filling in outside_addr and inside_addr and intf (on O2 its O2_ADSL2plus) - you can find a list of your box's interfaces by using nat iflist and associated addresses ip iplist):

nat mapadd intf=Internet type=nat outside_addr=your_external_ip_addr inside_addr=your_time_machines_ipv4_addr protocol=6to4

OR if you have a dynamic IP address (common these days) then use the following (and it will dynamically install the appropriate rule to permit your 6to4 IPv6 tunnel through when your router reboots (as suggested on he.net) - But to get it all working you will also need to use some sort of dynamic tunnel update as provided by he.net):

:nat tmpladd group=wan type=nat outside_addr= inside_addr=your_time_machines_ipv4_addr protocol=6to4

To get a full listing of existing mappings use: nat maplist expand=enabled If you need to change a mapping then you'll need to delete it first using nat mapdelete and then add the modified one. Once you've got the right mapping in place then you'll need to save the config so it is persistent between reboots by typing config save filename=user.ini (on O2 anyway - for others you'll need to check the default config file by: config list)

This article follows on from one on using my Time Machine as IPv6 6to4 tunnel/router - though this advice could also be relevant to someone just using a 6to4 tunnel from any device.