Friday, 25 September 2009

Handy OSX commands

List USB devices (a bit like lsusb on Linux)
On standard installation:
ioreg -c IOUSBDevice -l -w 0
Or using the developer tools:
IORegistryExplorer

Airport Wifi Info
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport
There are various arguments you can run it with -h to get a listing but the most useful are -I to get current wireless status, and -s to do a wireless scan.

Mount and mess with disk images
Here's how to mount a dmg:
hdiutil attach your_disk_image.dmg

List process' network connections
sudo lsof -i -P

Tweaking startup apps
- To disable startup items - add/rm a file called .disabled in their directory (i.e. a subdir of /System/Library/StartupItems/ or /System/Library/StartupItems/)
- launchctl -- Interfaces with launchd - in /Library/LaunchDaemons and similar
- Various custom ones; e.g. sudo "/Library/Application Support/VMware Fusion/boot.sh" --stop

Search using Spotlight on the command line
mdfind your_search_term (or mdfind -name file_to_find to look for file names).
There's also a few other related utilities like mdls to list file attributes etc. For more info see this useful post. It is also possible to enable the unix style locate command but it seems like a waste of space on OSX since you've already got Spotlight - though locate does provide for searching all files (only by name). However one can tweak Spotlight to search these files too...

Playing sounds on the cmd line
/usr/bin/afplay
Also afinfo gives you info on the file.

Print out OSX version
/usr/bin/sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'
Or use system profiler (both suggestions from here):
system_profiler SPSoftwareDataType


There's also other pages with similarly useful info like here.

[updated: 23mar10]

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";
    exit;
    
    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=0.0.0.1 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.

Tuesday, 26 May 2009

Skype codec selection

Ever wondered how to manually choose which codecs Skype uses when you make an audio call? Well here's how (by selecting the Skype codecs you don't want to use):
  • On Windows/Mobile you set this registry key (HKEY_LOCAL_MACHINE/SOFTWARE/Skype/Phone/Audio/DisableCodecs) to contain the codec's you don't want Skype to use (e.g. for Pocket PC you might want to disable higher CPU codecs: "ILBC G729 EG711U")
  • On Linux/OSX you add the disabled codecs inside these tags: <DisableCodecs> <\DisableCodecs> in the config.xml file (usually found in ~/.Skype/your_skype_username/config.xml). They need to be put into the (usually existing) <Call> tag which is within the <Lib> tag.
  • Furthermore you can actually force the use of a particular codec by using the <ForceCodec> tag/Reg key in the relevant place.
Skype has a wide range of codecs (e.g: SILK_WB_V3, SILK_NB_V3, ILBC, G729, EG711U, SVOPC, SILK, ISAC) which seems to get expanded every so often. Note: That disabling G729 may interfere with use of SkypeOut. Skype generally does a good job of automatically selecting the appropriate codec and its rate - unless you use this tweak - so be aware that Skype may not perform optimally when it's range of codecs is impaired.

There's also other fun stuff you can tweak - like adding a <video> section and make Skype use a particular resolution (you'll need to convert this to an appropriate Registry entry on Windows):
<captureheight>480</captureheight>
<capturewidth>640</capturewidth>

For an interesting read on Skype see columbia.edu, and for papers on performance see Politecnico di Bari and Politecnico di Torino.

[Updated: 16mar2012: More on location of Codec config tags]

Monday, 18 May 2009

Weird MagicCam error message from Google talk video device

Have you ever seen this error when attempting to run some capture software on OSX? (Note: The current process label in the error message is dependent upon which app you're running - in my case its one called vic):
[000:029] MagicCam 0: Current process: vic, Flash is loaded: no
[000:029] Error(magiccammac.cc:276): MagicCam 0: MagicCamOpen: Not an allowed process!

It is coming from the Google Talk's virtual video devices (but it's probably not actually causing any trouble directly - see below) - which are installed here:
/Library/QuickTime/Google Camera Adapter 0.component
And the MacCam related functions are in these two files:
/Library/QuickTime/Google Camera Adapter 0.component/Contents/MacOS/Google Camera Adapter 0
Run strings on it:
strings "/Library/QuickTime/Google Camera Adapter 0.component/Contents/MacOS/Google Camera Adapter 0" | grep -i magiccam)
and you get:
/Volumes/BuildData/PulseData/data/recipes/320452156/base/branches/googletalkplugin_release_branch/googleclient/talk/magicflute/magiccam/magiccammac.cc

Anyway it's not actually harmful and generally if you've a problem this is unlikely to be the cause of it. You can just [re]move the files as necessary to get rid the messages though your problem may well be somewhere else but at least you can eliminate it as a possible cause.

Friday, 1 May 2009

Just setup Time Capsule as my IPv6 gateway

So Apple have taken a lead in the drift towards IPv6 adoption (though it seems we really are getting to the end IPv4 as we know it) - their Time Capsule (TC) uses IPv6 out of the box for administration when using the AirPort Utility (Using a proprietary encrypted protocol AACP). It also has facilities for setup of an IPv6 [6in4] tunnel using IPv6 in IPv4 encapsulation (specifically IP protocol 41) as specified in RFC4213.

So to get connected to the Global IPv6 Internet (such as it is...) you need to go get a free tunnel endpoint from Hurricane Electric (or others) then use the AirPort Utility and select 'Manual Setup', then go to 'Advanced' and 'IPv6' then select 'IPv6 mode:' as tunnel and select 'Configure IPv6:' as Manually. The enter the addresses as given by your IPv6 tunnel provider. In the LAN IPv6 Address enter an address that has the same IPv6 prefix as the others but with a different host id - the bit after the "::/64" - just choose a number (well up to 8 hex digits separated by ':'s - no "::" prefix used if exactly 8 digits are used for host_id) which will form your TC's [Global] IPv6 address (e.g. your_prefix::FE:ED:CO:FF:EE). It's probably best to disable incoming connections as you could open your machine to IPv6 attacks.

If you're on a public IP address space then you're all set, however if like most of us your TC is behind a DSL router/NAT then you'll need to make hole in your firewall/NAT so Porotocol 41 gets in and out. If you're lucky enough to have a Linux based DSL router then this how to do it - login to you router. If you've got a Netgear router then you can enable telnet access by going to http://your_router/setup.cgi?todo=debug. And then telnet to the router and type the following (which I found here) - given your TC has the address 192.168.0.2:
iptables -t nat -A PREROUTING -i ppp0 -p 41 -j DNAT --to 192.168.0.2
iptables -t filter -A FORWARD -i ppp0 -p 41 -d 192.168.0.2 -j ACCEPT

You may not need to do the above on some routers - all tht may be necessary is enable pings on the external interface.

[update 2aug09]: If you've got a Thompson router then see my new blog entry.

And you should now be able to access the world of IPv6.... Check out these for starters ipv6.google.com, the old Kame dancing turtle, and quite a few others...oh and these too...

[updated/corrected 6in4 - 18nov09]

Wednesday, 29 April 2009

Encrypted Timecapsule backups

Timecapsule backups aren't encrypted which seems a little dumb - as if someone nicks your TC then they've also got all your data in the clear too. There's a simple procedure that this smart post lays out - but I've copied it here in case that page goes away as it is so handy:
  • Set up Time Machine to back up to an AFP drive. I don’t think this will work with a local hard drive.
  • Let Time Machine start backing up, then stop the back up. This will have created _.sparsebundle on the AFP drive.
  • Disable Time Machine.
  • Open a Terminal and run these commands (replace name_mac with your mac's name, and TC_drive_name with your TimeCapsule's network drive name - ls /Volumes to check):
    $ cd /Volumes/TC_drive_name/
    $ mv name_mac.sparsebundle name_mac-old.sparsebundle
    $ hdiutil convert -format UDSB -o name_mac.sparsebundle -encryption AES-256 name_mac-old.sparsebundle

    It will ask you for a password. Type in a password you won’t forget.
  • Double click the sparsebundle in the Finder (You should find it in your TimeCapsule network drive). You will be prompted for your password. Type that in and tick the “Remember password” check box.
  • Open /Applications/Utilities/Keychain Access and find name_mac.sparsebundle. Right click it and select Copy name_mac.sparsebundle.
  • Select System Keychain on the left hand side of Keychain Access and paste it in the main area. Allow this action if you are asked. Remember to lock the System Keychain when you are done.
  • If using Snow Leopard then (as suggested here) you'll need to copy "com.apple.TimeMachine.MachineID.plist" from the old to the new sparsebundle. You can do this by going to the volume using Terminal as above and then doing:
    $ cd /Volumes/TC_drive_name/
    $ cp name_mac-old.sparsebundle/com.apple.TimeMachine.MachineID.plist name_mac.sparsebundle
  • Unmount the volume and then tell Time Machine to get busy.
  • Time Machine should not have no problem backing up to the encrypted volume. If everything works as planned, feel free to delete the name_mac-old.sparsebundle
[updated: 21sept09, 21aug10]