Thursday, February 24, 2011

Connecting to HP ProCurve switches from Perl

I recently needed to get various information out of our switches, but didn't feel like manually logging into each one to get it. I tried to google up something that did it for me and failed, so I rolled my own script to connect to a number of HP ProCurve switches and get information from them using the Perl module Net::Telnet.

This is a simple example of how it can be done, hopefully to the help of the next person googling this. The below script makes various assumptions that are probably wrong for your network, like that all switches are reachable via domain names like sw12345.mgmt.

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Net::Telnet;

my $swpw = "hackmenot"; # Assumes same password for all switches.
my @switches = ("sw12345", "sw12346", "sw12347", "sw12348");

# Firmware versions that don't have the "Press any key" prompt.
my %nopress = (
"K.14.47" => 1,
"W.14.49" => 1,
);

foreach my $sw (@switches) {
my ($model, $version, $string, $trunks) = &get_information($sw);
printf "%s: %s (%s)\n loop-protect: %s\n trunks: %s\n\n",
$sw, $model, $version, $string, $trunks;
}


sub get_information {
my ($switch) = @_;

my @output;

my $session = new Net::Telnet(Timeout => 5,
Telnetmode => 0,
Prompt => '/'.$switch.'.*?# /',
Dump_log => "/tmp/procurve.txt", # Debug log.
Host => "$switch.mgmt"
);

# Figure out what model the switch is. To make this more exciting, HP has
# varied the output between different versions.
my ($prematch, $match) = $session->waitfor('/ProCurve.*?Switch.*\n/');
my $model = $match;
$model =~ s/[\r\n]//g;
$model =~ s/ProCurve //i;
$model =~ s/\s*J\d+[AB]\s*//i;
$model =~ s/\s*Switch\s*//i;

($prematch, $match) =
$session->waitfor('/(Firmware|Software) revision.*\n/');
$match =~ m/(Software|Firmware) revision (.*)/i;
my $version = $2 || "";
$version =~ s/[\r\n]//g;

# Some versions of the firmware don't have this prompt.
if (!$nopress{$version}) {
$session->waitfor('/Press any key to continue/');
$session->print("");
}

$session->waitfor('/Password: /');
$session->print($swpw);

$session->waitfor('/'.$switch.'.*?# /');

# Avoid the "more" prompt for long output.
@output = $session->cmd(String => "terminal length 1000");

# List the configuration to see what ports have loop-protect set.
@output = $session->cmd(String => "show running");
@output = grep(/loop-protect/, @output);
my $loop = join(", ", @output) || "";
$loop =~ s/[\r\n]//g;
$loop =~ s/loop-protect\s*//i;

# Check what ports are used for trunks.
@output = $session->cmd(String => "show trunks");
@output = grep(/Trk/, @output);
my $trunks =
join(" ", map { $_ =~ m/\s+(\d+)\s.*\s(Trk\d+)\s/ && $1 } @output);

$session->close;

return ($model, $version, $loop, $trunks);
}

Thursday, October 15, 2009

Acer Aspire One and Ubuntu Linux

I just bought an Acer Aspire One Pro A531H N270 netbook and immediately went on to install Ubuntu Linux (Jaunty Jackalope) on it (while keeping the original Windows XP installation available through dual boot). On the whole this was painless but there are a couple of snags.

Installation: I used the UNetbootin tool to create a bootable SD card to perform the installation, and this was painless. Normally I install from CD, but since the Aspire doesn't have one and I don't own a USB one, this was not an option.

Screen: Crisp and sharp, and with the right resolution immediately.

Webcam: Works fine out of the box. However, getting the microphone to work seems to require some manual installation that I haven't bothered with yet since I don't normally use my computers for anything that requires a microphone. Update: After upgrading to 9.10, the microphone works without any special tricks.

Sound: Works fine, but I wouldn't mind the volume going a bit higher. Update: It would be nice with a hardware volume control.

Network: The wired network worked fine immediately. The wireless didn't, but the instructions in this post fixed it, and I have since then had no problems with it.

SD card reader: There are two. The left one works fine, detecting cards inserted on the fly. I haven't tried the right-hand one.

Touchpad: Works fine. Ubuntu had sideways scrolling disabled by default, but that's just a matter of changing a checkbox in the settings.

External display: I haven't tried this connection yet. Update: I've tried once to get it to work and failed using Ubuntu 9.04. After a reboot to Windows XP it worked fine, so it seems like a software issue. Pressing Fn-F5 in Ubuntu did nothing at all.

Suspend: Works fine.

I've only used this machine for a few hours yet, but so far it feels nice and I don't have any real quibbles about it. Update: A few months later, and I'm still happy with the machine.

Update: The update to Ubuntu Karmic Koala was painless.

Andra bloggar om: , , ,
Technorati Technorati tags: , , ,
intressant.se

Tuesday, January 6, 2009

Dual booting Ubuntu Linux and Windows Vista on a Toshiba Satellite L300D 13J

For christmas last year we got ourselves a Toshiba Satellite L300D 13J laptop. The idea was mostly to get the kids off Camilla's company laptop. The reason I got this particular model was that it was available locally for a reasonable sum and filled the requirements we had, not that it was very much better than anything else. As far as I could tell, most of the machines in a given price bracket were pretty much the same.

It turns out that it's impossible to get a laptop over the counter here without paying the Microsoft tax, and to make it worse you get stuck with Vista. Since our kids occasionally want to play Windows stuff I wanted to leave Vista on the machine, but still install Ubuntu Linux 8.10 (Intrepid Ibex) on it as well. I thought that this was something that about a million people would have done before so that information about how to do it would be all over the internet, but that turned out not to be so. One of the places I found that had something was this, but it wasn't very useful for me since it assumed that you had real Vista installation media.

The machine we got was kind of preinstalled with Vista and we got no CD or DVD with the OS. Instead, when you first boot the machine, it performs various post-installation tasks and then offers to burn a restore DVD, so I let it do this.

Since I now had a disk that could take me back to where I started, I felt a little braver. I put in a Ubuntu installation CD and booted from that. It booted happily and showed me the partitioning tool. This showed that the disk already had more than one partition. Apparently, about half the disk was used by some mystery partition that I assume is where the Vista installation came from. The other half of the disk contained the actual Vista installation and user files. Thus, a normal user will only get half the disk space they paid for. I didn't feel like messing too much with the partitioning, so I simply let Ubuntu shrink the Vista partition to about half its original size (i.e. a quarter of the total of the disk). I then proceeded to install Ubuntu on the new free disk space that I had just created. The installation process was totally painless.

After finishing the Ubuntu installation, I rebooted to Vista. It said something about the system changing and then started something that looked like the same initialization process that happened the first time I started the machine. True enough, I had to redo all the settings I had done previously. Since I never created any files I don't know it it would have wiped those as well, but at least any settings seemed to be lost. It seems like a good idea to do this after a good backup or even better on an unused machine.

Once Vista was happy again (including after a reboot), I restarted the machine again and started up Ubuntu. This also came up without any problems, including working wifi and webcam.

Andra bloggar om: , , , , , , , ,
Technorati Technorati tags: , , , , , , , ,
intressant.se

Tuesday, March 11, 2008

Wireless hotspots: hot or not?

Ericsson's marketing manager Johan Bergendahl predicts that wireless hotspots will be the telephone booths of the broadband age, i.e. something that will soon be hard to find. Instead he believes in mobile broadband.

For those that need access to broadband absolutely anywhere there isn't much to choose from apart from telephony-based broadband. I think, however, that wireless hotspots will be around for a long time yet.

The important difference, and the reason that Ericsson have the opinion that they do, is that mobile broadband always costs money for the one using it. A wireless hotspot doesn't have to be free either, but it can be. My take on this is that it will be more and more common for stores, cafes, malls and other places that people come to will offer wireless connections to everyone in range. I would be surprised if it isn't soon considered rude if a store doesn't offer network connectivity to people in it. Likewise, services like Fon will offer wireless connectivity to people in exchange for them offering their own connectivity to others.

Andra bloggar om: , , , , , , ,
Technorati Technorati tags: , , , , , , ,
intressant.se

Tuesday, October 23, 2007

How not to sell music

Once again, the music industry demonstrates that it has no clue what to do when it comes to handling digital music. They are now selling music on USB sticks instead of as CDs, hoping to replace the ailing single format. To do this, they are replacing a £2.99 format with a £4.99 format. If this would work, it would mean that customer would be swimming in USB-sticks with no apparent use, since the music would be transfered to a storage disk for easy access as soon as you bring it home, just like a CD gets ripped once and then archived in the basement.

Not only is it idiotic from an environment to make customers buy electronics they don't need more than once, it is also idiotic from the music industry's survival perspectice to try to replace a dying format with another one that is more expensive.

A digital music track costs next to nothing to store since they are only bits on a disk. Customers expect the price for digital music to be significantly lower than the old formats where records had to be pressed, covers printed, albums distributed, store inventory kept, and so on. Today, the only thing that is needed to market music is a web site where you can buy mp3s online, and the costs for "producing" an mp3 like this are of course infinitesimal compared to old-style records. The natural thing would be for prices to reflect this. If they don't, customers will move over to getting their music via illegal downloads which are already easily available and cheap. It's as simple as that. The music industry has to add value to an existing service that is free. The only way I can see that happening is for them to drop prices to about $1/album or $.1/track and providing fast, rock-solid downloads with no customer-unfriendly DRM.

Andra bloggar om: , , , ,
Technorati Technorati tags: , , , ,

Thursday, August 30, 2007

Microsoft buys persistent IMs

Microsoft has acquired a company called Parlano which creates whan they call a persistent chat. For some time now, Microsoft has produced Office Communications Server (previously known as Live Communications Server, LCS). This is a SIP-based system that allows users to (among other things) send IMs to each other, just like can be done using for instance MSN or ICQ. Indeed, the OCS/LCS client can also talk to MSN servers.

The SIP protocol allows both person-to-person communication and conferencing. I'm not sure whether OCS/LCS actually supports IM conferencing (what most people would call a chat room), but there are no technical obstacles.

What Parlano makes is a system that allows people who have been offline to read up on a conversation when they reconnect. You know, the kind of thing that ICQ users take for granted. The difference is that the Parlano system handles multi-person chats, and also that it handles multiple protocols. According to a Parlano product page, apart from LCS it will also handle AOL, Yahoo, and MSN. I can't find any mentions of SIP on the Parlano page, so I don't know whether their system uses that or some other homebrew solution to talk to LCS. Since this is Microsoft, I wouldn't be surprised if this was a non-standards-based solution. Rather the opposite, actually.

Andra bloggar om: , , , , , , , , , , , , ,
Technorati Technorati tags: , , , , , , , , , , , , ,

Monday, August 27, 2007

The insanity of ATX power supplies

On Friday, the power supply for my work station gave up with a fizzle. This morning, a new power supply was delivered to me and I started mounting it. Doing anything hardware-related in a modern PC is painful, but this seemed unusually stupid.

The power supply in itself is mounted in the chassis with four screws, all of them easily accessible from the back of the computer. So far, so good. In the other end of the power supply, inside the computer, a tangled octopus of cables sprouts. Most of them are equipped with multiple connectors along the length of the cable. Lots of these cables are strapped to the chassis in hard-to-reach places or pulled through tiny holes that are hard to reach, and that force you to wiggle those damn connectors long and well before being able to pry the cables out.

One good thing should be noted: all the cables have different connectors that can't be forced into the wrong socket, and the connectors are not symmetrical to the only way the connectors fit is the right way.

A bad thing was that it wasn't possible to get the old power supply out or the new one in without using force to bend a couple of the petals of the huge cooler thingy that is attached to the CPU.

The old power supply has the following stuff coming out of it:

  • Big cable for the motherboard.
  • Smallish cable also for the motherboard, but in a different place.
  • Another pretty big cable that I don't know what it's for.
  • Very small cable which is actually labled(!): "PSU FAN MONITER CONNECTOR" (sic!).
  • Cable with two SATA disk power connectors.
  • Cable with two regular hard disk power connectors.
  • Cable with two regular hard disk power connectors and a floppy power connector.
  • Cable with three regular hard disk power connectors and a floppy power connector.
  • Cable with two regular hard disk power connectors, but labeled "FAN ONLY".


Not surprisingly, my work station does not actually have nine hard disks or other media devices, and neither does it have two floppy drives. There are several meters of cables here that won't ever be used.

I wonder how long it will be until someone comes up with the idea that a power supply only needs one cable, connected to the chassis. The cables can then be integrated in the chassis, with small cables sticking out in drive bays, close to the motherboard power connector, etc. Having to subdue an octopus just to exchange a computer component feels unneccessary.

Andra bloggar om: , , ,
Technorati Technorati tags: , , ,