Monday, November 30, 2009

Create Mega Android Playlists from PC

Wanting to create a large playlist for my HTC Hero android based phone, I found out this is a fairly painful task since the obvious method involves adding songs one by one!

Fear not fellow androiders, here is how to create mega playlists easily (although it does involve typing a command OMG :) )

1- Plug in the phone over USB. My phone appears as drive G:
2- Open a terminal window, and "cd" into the Folder containing the music you would like to make a "playlist". In my case

g:
cd MP3/80sMusic

3- Here comes the magic

dir /B > 80s-best-Music.m3u
exit

4- Et voila, the terminal window exits, safely remove your USB disk, turn off the USB connection from the phone and that is it!

Addendum for Linux users
1- Mount your phone on some directory, and "cd" to it. In my case

sudo mount /dev/sdb1 /media/androidy
cd /media/androidy

2- Create the playlist file

cd MP3/80sMusic
ls > 80s-best-Music.m3u

3- Eject and Et voila. It's really almost identical to the Windows case

cd / ; sudo umount /media/androidy


I was pleasently surprised to find that in Android ALL music apps share the same playlists. So that newly created playlist is seen by the built-in Music application, as well as with the 3rd party Music player MixZing. It is also pleasantly surprising that Android seems to scan the whole folder structure for the .M3U files wherever they may be and use them as playlists! Sweet

Thursday, November 19, 2009

Taking down your CPUs

echo 0 > /sys/devices/system/cpu/cpu1/online

Nov 19 11:59:35 localhost kernel: CPU 1 is now offline
Nov 19 11:59:35 localhost kernel: SMP alternatives: switching to UP code

Since my CPU is/was dual core, it's now single .. and thus the kernel has switched to UP code... neat !

Saturday, August 29, 2009

Google Chrome Multiple Home Pages

Recently I started using Google's browser Chrome (well technically chromium) on Linux for my browsing needs. It is very fast, low on CPU and Memory, I quite like it. I am now also sure Flash plugin is teh CPU hog pig :) Anyway, one really cool feature I missed from Firefox was the ability to set multiple pages as the homepage. The thing is, I follow quite a lot of tech news sites, and I need to check them every now and then. In firefox, I'd just click the Home button, and it would open all of them, I could not find this functionality out of the box with Chrome. What is a geek to do ? Well of course write some javascript :)

So, here is how I resolved this issue:
- Open a new tab, the bookmarks toolbar appears, right click it choose add page
- Choose a Name for the bookmark
- In the URL field, paste the following javascript

javascript:(function(){ window.location.href='http://site1.org/'; window.open('http://site2.com/'); window.open('http://site3.com/'); window.open('http://site4.com/'); })();


That is it :) Keep adding more sites as much as you want. Pretty straightforward, but I thought I'd blog it since it might not be all that obvious

Tuesday, July 21, 2009

8 sockets, 64 cores, 128 threads, Yummy!

The Windows task manager almost looks funny! enjoy

Thursday, July 2, 2009

English/Arabic Voice/Voice iPhone translator

Amazing video! The future is now!

Wednesday, July 1, 2009

KDE 4.3 coming




Tuesday, June 30, 2009

Network Scan for Conficker

The conficker worm is a pretty nasty one! How do you scan if a machine on your network is infected ?

In this article we'll be using the awesome open-source nmap network scanning engine. In this example I will be preforming my scan from a Linux box. However you can use other OSs.


wget http://nmap.org/dist/nmap-4.90RC1-1.i386.rpm
rpm -Uvh nmap-4.90RC1-1.i386.rpm


It is recommended that you get the latest nmap from their download page. Next, launch nmap on the local network IP range, in this example it is 192.168.96.0/22, but YMMV. The interesting argument here is the --script which utilizes the NSE (Nmap scripting engine) in order to assess whether or not the current windows machine nmap is connected to is vulnerable. So let's launch the scan


nmap -PN -T4 -p139,445 -n -v --script smb-check-vulns,smb-os-discovery --script-args safe=1 192.168.96.0/22


Once the scan has completed Identify the potentially infected machine on the LAN. An infected machine would result in nmap output similar to


Host script results:
| smb-os-discovery: Windows XP
| LAN Manager: Windows 2000 LAN Manager
| Name: WORKGROUP\LAME-WinXP
|_ System time: 2009-06-30 10:47:12 UTC+3
| smb-check-vulns:
| MS08-067: CHECK DISABLED (remove 'safe=1' argument to run)
| Conficker: Likely INFECTED (by Conficker.C or lower)
|_ regsvc DoS: CHECK DISABLED (add '--script-args=unsafe=1' to run)


Once identified, you can use the great kkiller tool from kaspersky labs to clean the infected machine

You can find the latest kkiller from the following page page as well

Have fun, patch your broken windows, or better yet, learn some *nix foo or bar :)

Wednesday, June 3, 2009

OpenSolaris 2009.06 PV under Xen Centos5 dom0

OpenSolaris 2009.06 has been recently released. Since ZFS offers a lot of flexibility and advantages as a storage platform, many would be interested in running the opensolaris stack. In this article I'll be installing OpenSolaris 2009.06 para-virtualized under a centos-5-x64 dom0. This setup has the advatange of running OpenSolaris on storage controllers that may not have native solaris driver support. Not that that would be recommended, however, it might be useful for testing. So, let's begin

- Install a minimal Centos-5-x64 installation. I installed the OS on a 20G partition, while the rest of the disk was formatted as LVM partition for creating logical volumes for xen guests to live on

- Install the latest Xen stack. I will be installing Xen-3.4. This is highly recommended since the bundled boot-loader pygrub has the ability to mount ZFS block devices.


[root@xen2 yum.repos.d]# cat > /etc/yum.repos.d/gitco.repo << EOF
> [gitco]
> name = Red Hat Enterprise $releasever - gitco
> baseurl = http://www.gitco.de/repo/xen3.4.0
> enabled = 1
> protect = 0
> gpgcheck = 0
> EOF


- Now let's install the required virtualization stack


[root@xen2 yum.repos.d]# yum install xen-libs.x86_64 bridge-utils.x86_64 qemu.x86_64 gtkglext-libs.x86_64 gtk-vnc.x86_64 gtk-vnc-python.x86_64 cyrus-sasl-md5.x86_64 libvirt.x86_64 libvirt-python.x86_64 python-virtinst virt-manager.x86_64 kernel-xen.x86_64 xen.x86_64 virt-viewer.x86_64 libvirt.x86_64 gnome-applet-vm.x86_64



Check that your menu.lst file has been updated to point to the newly installed Xen

[root@xen2 yum.repos.d]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.1.10.el5xen)
root (hd0,0)
kernel /boot/xen.gz-3.4.0
module /boot/vmlinuz-2.6.18-128.1.10.el5xen ro root=LABEL=/ rhgb quiet
module /boot/initrd-2.6.18-128.1.10.el5xen.img
title CentOS (2.6.18-128.el5)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-128.el5 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.18-128.el5.img


- Reboot into your new environment, and check you are booted on Xen-3.4


[root@xen2 ~]# xm dmesg | head
__ __ _____ _ _ ___
\ \/ /___ _ __ |___ /| || | / _ \
\ // _ \ '_ \ |_ \| || |_| | | |
/ \ __/ | | | ___) |__ _| |_| |
/_/\_\___|_| |_| |____(_) |_|(_)___/

(XEN) Xen version 3.4.0 (root@gitco.tld) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) Fri May 29 21:39:26 CEST 2009
(XEN) Latest ChangeSet: unavailable
(XEN) Command line:
(XEN) Video information:


- Now we're ready to begin :) Make a folder and download the ISO in it


[root@xen2 ~]# mkdir -p /xen/osol/ && cd /xen/osol && wget http://genunix.org/distributions/indiana/osol-0906-x86.iso


- Let's loop mount the iso, extract the paravirt kernel and micro-root


[root@xen2 osol]# mkdir -p /mnt/loop
[root@xen2 osol]# mount -o ro,loop osol-0906-x86.iso /mnt/loop
[root@xen2 osol]# cp /mnt/loop/boot/amd64/x86.microroot /mnt/loop/platform/i86xpv/kernel/amd64/unix .


- Construct the Xen installation-time configuration file


[root@xen2 osol]# cat > osol0906install << EOF
> name = "osol0906install"
> memory = 1024
> vfb = [ 'type=vnc,vnclisten=127.0.0.1,vncdisplay=0' ]
> disk = ['file:/xen/osol/osol-0906-x86.iso,6:cdrom,r',
> "phy:/dev/vgxen/osol,xvda,w" ]
> vif = [ "mac=00:16:36:10:f5:69,bridge=eth1" ]
> on_reboot = "destroy" # comment out this after installation
> kernel = "/xen/osol/unix"
> ramdisk = "/xen/osol/x86.microroot"
> extra = "/platform/i86xpv/kernel/amd64/unix - nowin -B install_media=cdrom"
> EOF


- Create the logical volume for the OpenSolaris installtion


[root@xen2 osol]# lvcreate -L 15G -n osol vgxen
Logical volume "osol" created
[root@xen2 osol]# ls -l /dev/vgxen/osol
lrwxrwxrwx 1 root root 22 Jun 3 22:14 /dev/vgxen/osol -> /dev/mapper/vgxen-osol



- Start the Xen VM, and hit enter a few times for the defaults


[root@xen2 osol]# xm create ./osol0906install -c
Using config file "././osol0906install".
Started domain osol0906install (id=1)
v3.4.0 chgset 'unavailable'
SunOS Release 5.11 Version snv_111b 64-bit
Copyright 1983-2009 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Hostname: opensolaris
Remounting root read/write
Probing for device nodes ...
NOTICE: xdf@6: failed to read feature-barrier
NOTICE: xdf@51712: failed to read feature-barrier
Preparing live image for use
Done mounting Live image
USB keyboard
1. Albanian 23. Lithuanian
2. Belarusian 24. Latvian
3. Belgian 25. Macedonian
4. Brazilian 26. Malta_UK
5. Bulgarian 27. Malta_US
6. Canadian-Bilingual 28. Norwegian
7. Croatian 29. Polish
8. Czech 30. Portuguese
9. Danish 31. Russian
10. Dutch 32. Serbia-And-Montenegro
11. Finnish 33. Slovenian
12. French 34. Slovakian
13. French-Canadian 35. Spanish
14. Hungarian 36. Swedish
15. German 37. Swiss-French
16. Greek 38. Swiss-German
17. Icelandic 39. Traditional-Chinese
18. Italian 40. TurkishQ
19. Japanese-type6 41. TurkishF
20. Japanese 42. UK-English
21. Korean 43. US-English
22. Latin-American
To select the keyboard layout, enter a number [default 43]:
1. Arabic
2. Chinese - Simplified
3. Chinese - Traditional
4. Czech
5. Dutch
6. English
7. French
8. German
9. Greek
10. Hebrew
11. Hungarian
12. Indonesian
13. Italian
14. Japanese
15. Korean
16. Polish
17. Portuguese - Brazil
18. Russian
19. Slovak
20. Spanish
21. Swedish
To select desktop language, enter a number [default is 6]:
User selected: English
Configuring devices.
Mounting cdroms
Reading ZFS config: done.

opensolaris console login: jack
Password:
Sun Microsystems Inc. SunOS 5.11 snv_111b November 2008
jack@opensolaris:~$ pfexec uname -a
SunOS opensolaris 5.11 snv_111b i86pc i386 i86xpv Solaris
jack@opensolaris:~$
jack@opensolaris:~$ ifconfig -a
lo0: flags=2001000849 mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
xnf0: flags=1004843 mtu 1500 index 2
inet 192.168.96.121 netmask fffffc00 broadcast 192.168.99.255
lo0: flags=2002000849 mtu 8252 index 1
inet6 ::1/128
xnf0: flags=2004841 mtu 1500 index 2
inet6 fe80::216:36ff:fe10:f569/10


- Note that once the installation system boots up, we login with username/password = jack/jack. We use "ifconfig -a" to check the system's IP address (was configured by DHCP, VM NIC is bridged to physical host's eth1). The IP in this case is 192.168.96.121

- Now here comes a bit of a tricky part, the Xen console is text only, the OpenSolaris installtion is GUI only (yuck?) In order to get GUI access we will use a built in VNC service in the OpenSolaris Live CD. To get the password for the default vnc session, perform the following command on the Centos Host machine



[root@xen2 osol]# xenstore-ls | grep pass
passwd = "guzc/VCg"


- Connect to the live CD and launch the installer


vncviewer 192.168.96.121:0


Continue with the installer GUI

1-osol0906-pv-installer

2-osol0906-pv-installer-going

- Once done, click Reboot on the installer. The VM actually powers off, which is what we've configured and what we need.

- Create the run-time Xen config file


[root@xen2 osol]# cat > osol0906pv << EOF
> name = "osol0906pv"
> memory = 2048
> vfb = [ 'type=vnc,vnclisten=127.0.0.1,vncdisplay=0' ]
> disk = [ "phy:/dev/vgxen/osol,xvda,w" ]
> vif = [ "mac=00:16:36:10:f5:69,bridge=eth1" ]
> bootloader = '/usr/bin/pygrub'
> EOF



- Start the VM and enjoy :)



[root@xen2 osol]# xm create -c ./osol0906pv
Using config file "././osol0906pv".
Started domain osol0906pv (id=2)
v3.4.0 chgset 'unavailable'
SunOS Release 5.11 Version snv_111b 64-bit
Copyright 1983-2009 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
NOTICE: xdf@51712: failed to read feature-barrier
Hostname: osol0906pv
Configuring devices.
Loading smf(5) service descriptions: 150/150
svccfg import warnings. See /var/svc/log/system-manifest-import:default.log .
Reading ZFS config: done.
Mounting ZFS filesystems: (6/6)
Creating new rsa public/private host key pair
Creating new dsa public/private host key pair

osol0906pv console login: dev
Password:
Sun Microsystems Inc. SunOS 5.11 snv_111b November 2008
dev@osol0906pv:~$ pfexec uname -a
SunOS osol0906pv 5.11 snv_111b i86pc i386 i86xpv Solaris
dev@osol0906pv:~$



Hope that's useful to someone out there

Saturday, May 30, 2009

Traffic accounting with SNMP and Python on Windows

If you're not on a flat-rate ISP data-plan, and your ISP made you pay extra last month such as myself :) You might be interested in monitoring your home bandwidth. A nifty little features of most routers or ADSL modems, is support for SNMP. Since both me and my old folks use the same ADSL line, any host based monitoring solution wouldn't really work. I had to monitor the usage using SNMP. Since my folks are using Windows, the solution had to work on that. The solution overview is:

1- Enable SNMP on ADSL modem
2- Use a windows scheduled task to run a windows Batch file, that uses SNMP-tools for windows to pull data from the router
3- Use a windows scheduled task to run a python script that processes the batch file output and computes the total traffic

Data from the batch files are written in a file signifying the current month (example 05.txt for May). Here is the code for the batch file




cd e:\traffic

e:\

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B

FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B



echo %mm%

snmpget.exe -c public -O v -v 1 192.168.11.1 .1.3.6.1.2.1.2.2.1.10.12 >> %mm%.txt



Note that the IP 192.168.11.1 should be replaced with the internal IP of your ADSL router. Also, the SNMP OID .1.3.6.1.2.1.2.2.1.10.12 (symbolically: IF-MIB::ifInOctets.12) is the incoming octets on network interface "12". You might need to change that last "12" to represent your network topology. You can use the "snmpwalk" command to list your interface names like:

snmpwalk -c public -v1 192.168.11.1
this yields
...
IF-MIB::ifDescr.12 = STRING: ppp0
...

I know that my ppp0 is the link to my ISP, so that's the interface I used

And here is the code for the python script



# -*- coding: utf-8 -*-

import glob

import locale

import os

locale.setlocale(locale.LC_ALL, '')

reports = sorted(glob.glob('??.txt'))

totalsReport = open('totals.txt','w')

totalsReport.write(' Month      Traffic \n')

totalsReport.write('====================\n')

for report in reports:

        datastring = open(report,'r').readlines()

        data = [ int(datastring[i].strip().split()[1]) for i in range(len(datastring)) ]

        diff = [ data[i+1] - data[i] for i in range(len(data) - 1) ]

        trafficDeltas = [ (data[i+1],diff[i])[diff[i] > 0] for i in range(len(diff)) ]

        totalTraffic = sum(trafficDeltas)

        totalsReport.write(' %s => %s \n'% (report.replace('.txt','') , locale.format('%d', totalTraffic, True)) )



totalsReport.close()




Glancing over the Python code, you can already see I'm a list comprehension addict :) The code reads the snmp bytes values from ??.txt (example: 05.txt), computes bandwidth deltas, handles counter resets (32bit overflow, or router loosing power) and computes totals. Then writes the total to a file named "totals.txt"

This solution is resistant to the router loosing power and resetting its internal traffic counter back to zero. This is because the data is continuously being saved to non-volatile medium (PC's hard-disk). Also, the Windows PC running those two scripts, does NOT need to be running 24x7 .. Just most of the time. If however the PC is powered off, AND the modem power cycles or hangs, you might loose some accuracy, the results will still be fairly valid though. Hope that's helpful to anyone out there

Google Wave, me likes

Check this out! Email+IM+Wiki+RealTimeCollaboration+Documents+Workflows+ServerSideBots+GoogleMagic+OpenStandards = Google Wave

This is the "Wave" of the Future ;)

Wednesday, May 27, 2009

Waiting for Fedora 11

Monday, May 25, 2009

Nexenta 2.0 is out

Check out the googley style toons at
http://www.nexenta.org/os

VMs over ZFS rock

when configuring some complex task over a server, sometimes things go bad (corrupt files, wrong versions, bad data in DB ... etc) and sometimes it's really not easy to undo everything such that you're sure the machine is in a known-good-n-clean state. This is where VMs over ZFS rock!

while self.isPatient():
ssh vm poweroff;
zfs rollback vm@someTimeWhenThingsWhereGood
VBoxManage startvm vm
self.letsTryAgain()

Hyper cool! Snapshots and ease/reliability of backups/restores are about one of the most important things why I love virtulization.

Wednesday, May 20, 2009

Killing Virii with Gentoo and Kaspersky

Sorry but if you pronounce kaspersky to rhyme with whisky, the title isn't going to sound as jiggly as it should ;) I used to pronounce it to rhyme with "sky" but apparently that's incorrect. Anyway, I've been a long time admirer of the Kaspersky AV engine. And today it has saved someone's a$$ one more time ;)

A friend of mine, who is pretty technical, well he maintains windows drivers for a living, so that sure makes him a hot-shot techy in anyone's book. That friend's laptop caught a nasty virus. In his own words, he was only downloading some power point presentations (ugh), when the miserable closed source proprietary OS he's running (euhm Vista) became infected. He was using Google's chrome browser, so the possibility of having been infected through a browser exploit remains pretty low in my opinion. Especially that Chrome auto-updates itself, thus fixing any potential security holes. My first impression was that he got infected through an exploit in MS Office 2007 (yuck). Anyway, with me trying to help him clean up the laptop, we tried the following

- Tried installing Symantec's AV suite. That totally fails to even install. What a piece of crap. Symantec's ware is highly over-rated IMO. I used to really like Norton stuff, back in the days of Norton's DiskDoctor .. those were the days :D

- Tried installing the tried and true MalwareBytes, which did detect and clean a whole bunch of malware, however, much to my surprise, the problem persisted. MalwareBytes is a cool piece of anti-malware, it has worked fantastically for me multiple times, but this time it wasn't enough!

- Having wasted a couple of hours on this already, I wanted to fire some Kaspersky power on the problem. I visited http://devbuilds.kaspersky-labs.com/devbuilds/RescueDisk/ and downloaded a Live CD image Burned the iso, and booted!



Now this Live CD is absolutely cool, it's a customized build of Gentoo linux (w00t!) that automagically detected the hardware, connected to the network, started an X server, launched a customized icewm environment with Kaspersky's "K" logo as the "start" button down below. I was impressed, and through that GUI I could launch Kaspersky's AntiVirus tool.

The first thing it did was to auto-update itself over the internet. Most definitely needed. Afterwards it located and mounted all Windows NTFS partitions, and I was presented with options to scan them. I chose to scan the c: drive. Scan has begun, the scan tool sports a nice looking GUI, although it can be a bit confusing. Anyway scanning has started churning on the hard-disk. It was a bit slow, took around 3 hours for a 100G c: drive!




But I'll sure take slow and reliable over anything else every time! At the end, Kaspersky has located hundreds of infected executable files. I chose to disinfect them. It started disinfection one by one. This took around 20 minutes or so as well. Rebooting after that, windows came up finally clean . The system is working normally again, sigh!

All in all, Kaspersky proved to be a reliable tool. Kudos to their team for providing a top notch Linux based Live CD for free, that updates itself and provides adequate disinfection for free. Thank you Kaspersky. I will surely recommend you guys in the future. This is one AntiVirus tool I will be sure to remember, when a friend comes knocking on my door. Note however, that they're not the only game in town, others like Avira, and BitDefender and others as well offer Live CD "rescue-disks" as they are called. Hope this post helps anyone out there.

Wednesday, April 22, 2009

Why We Hate Micro$oft

Did you ever wonder, why "those people" hate Microsoft
If you have, and if you really honestly truly want to gain a better understanding, put down your MS lover hat, and feast your eyes on the following Master-Piece document produced by "The European Committee for Interoperable Systems". The document named  "Microsoft - A History of Anticompetitive Behavior and Consumer Harm"

You can read the an introductory article + the full document (scroll down a couple of pages) at

Beware though, it's not a short read. It's more of a week-end type of thing. However, to wet your appetite, here are a couple of quotes

Killing Dr-Dos: The OS monopoly

"The approach we will take is to detect dr [DOS] 6 and refuse to load. The error
message should be something like 'Invalid device driver interface.'"
--Phillip Barrett, Microsoft Windows Development Manager


Killing Word-Perfect: The Office Monopoly

"I have decided that we should not publish these [Windows 95 user interface]
extensions. We should wait until we have a way to do a high level of integration
that will be harder for likes of Notes, WordPerfect to achieve, and which will give
Office a real advantage.... We can't compete with Lotus and WordPerfect/Novell without this."
--Bill Gates, Microsoft founder and then-CEO


Killing Java: The language Monopoly

"[W]e should just quietly grow j++ share and assume that people will take more
advantage of our classes without ever realizing they are building win32-only java
apps."
--Microsoft's Thomas Reardon




That's enough for a teaser :) Enjoy reading the rest of the document