Wednesday, July 24, 2013

Calculating distances in meatspace

I'm working on an automated provisioning system for a very large VPN network. For each new VPN client, I need to select a headend site where VPN tunnels should land. The only data available is that which I can get from the sales and billing systems. This system offers me the zip code of the install site.

Using the zip code of the install site, and the known zip codes of my various head-end sites, I'm able to select the destination for the primary and secondary VPN tunnels.

It's not perfect (physical location often has little to do with network path), but it's better than nothing. I haven't decided how to handle non-US sites yet.

I'm using a database of US zip codes found here, and a very dirty perl script. The script grabs the latitude and longitude of two zip codes from the database, and prints the mileage between them as calculated using the Haversine formula for great circle distance.

It runs like this:


Christophers-MacBook-Pro:scripts chris$ zipdistance.pl 95134 60614
1837 miles
Christophers-MacBook-Pro:scripts chris$

The script:


#!/opt/local/bin/perl
use GIS::Distance;

my $dbfile="/Users/chris/Downloads/zipcode.csv";
my $lat1,$lon1,$lat2,$lon2;

sub usage{
  printf "Usage: $0 <zipcode> <zipcode>\n";
  exit;
}

if (@ARGV != 2) {usage;};
unless ($ARGV[0] =~ /[0-9]{5}/) {usage;}
unless ($ARGV[1] =~ /[0-9]{5}/) {usage;}

my @sorted = sort @ARGV;

open(DB, '<', $dbfile);

FIRST: while (<DB>) {
  if ($_ =~ /^.$sorted[0]/) {
    (my $trash,my $trash,my $trash,$lat1,$lon1)=split(",",$_);
    my $i;
    ($i) = $lat1 =~ /"([^"]*)"/; $lat1 = $i;
    ($i) = $lon1 =~ /"([^"]*)"/; $lon1 = $i;
    last FIRST;
  }
}

SECOND: while (<DB>) {
  if ($_ =~ /^.$sorted[1]/) {
    (my $trash,my $trash,my $trash,$lat2,$lon2)=split(",",$_);
    my $i;
    ($i) = $lat2 =~ /"([^"]*)"/; $lat2 = $i;
    ($i) = $lon2 =~ /"([^"]*)"/; $lon2 = $i;
    last SECOND;
  }
}

if ("$lat1" == "" || "$lat2" == "") {
  printf "Unknown distance\n";
  exit 1;
}

my $gis = GIS::Distance->new();
my $distance = $gis->distance( $lat1,$lon1 => $lat2,$lon2 );
printf ("%d miles\n",$distance->miles());




Monday, July 22, 2013

Network Toolkit

My case full of network doodads always generates lots of questions when people see it for the first time. I don't carry dedicated iPhone chargers anymore, but Apple cube chargers forgotten behind hotel nightstands is where this started.

With this kit it is immediately apparent when something is missing, so things tend to not get left behind.

The limited space has driven me to find the best and most compact solutions to all of my problems. I'm really pleased with everything that's in here. I'm also aware that it's super nerdy.


The case itself is a Duluu Essential case for iPad. It's a nice semi-rigid clamshell type case. I've made two modifications:

  1. Removed the padded "page" between the two halves. This thing was intended to keep the stuff in the pockets on the left from scratching the iPad on the right. It also served as an iPad stand.
  2. I removed the original zipper pulls, replaced them with a repair part because the square corners of the original pulls tended to cause problems.
On the right side of the case I've installed a bit of floor padding foam (this kind of thing, but mine came from Harbor Freight Tools), with cutouts to hold all of my stuff. Cutting the foam is tedious, requires a very sharp blade.

So, what do I carry with me?

  1. Industrial Sharpies - The "industrial" version because the hyperbolic red label always cracks me up.
  2. Apple Video adapter, cheap PL2303-based serial adapter
  3. Silver Sharpie
  4. 6" micro and mini USB cables, earplugs
  5. Dell PU705 blutooth mouse - There is nothing special about this mouse, except that it uses two batteries, rather than one. Those batteries are AAA nimh batteries inside AAA to AA converter sleeves so that they interchange with the batteries in item 16 and can always remain with their charge/discharge buddy. A note about NiMH batteries: It's important to get low self-discharge batteries (sometimes marketed as "pre-charged") in applications involving long periods of disuse. These type of cells tend have a lower capacity than traditional NiMH cells.
  6. Aluminum Pill bottle - Full of pain killers. Network pain. It's a nice bottle with a threaded cap and an O-ring. Amazon seems to have screwed up the product image. The linked product is what I bought, even though the picture looks different right now.
  7. Apple MagSafe 2 Adapter
  8. NEMA 5-15R to IEC 60320-C14 Adapter - I shaved off the plastic lump opposite the NEMA receptacle's ground conductor so that it fits in the case better. Lets me charge my laptop in a server rack.
  9. Really cheap USB to Ethernet adapters from eBay. USB Device ID 0x9700 0x0fe6. I'm using the driver from here in OS X, hope it's not full of malware.
  10. Fenix LD01R2 flashlight - Surprisingly bright, contains a single alkaline AAA, so that in a pinch, I can harvest a battery from either the mouse or the serial adapter.
  11. Very short Cisco console cable. Thumbscrews replaced with nuts so that it attaches to my RS232 adapter.
  12. Weibetech Mouse Jiggler (slow version) - Looks like a USB flash drive, really it's a screen-lock defeater. It has saved the day countless times. Computers think it's a USB mouse. It moves the cursor imperceptibly, perhaps 1 pixel of movement per minute. Good for watching webinars, doing presentations, etc... Also, makes you show up as "active" in IM applications. The "fast" version is useless, except as a prank. Crazymouse!
  13. Picquick Multique - Surprisingly high quality compact screwdriver kit, made in Canada.
  14. Olfa SVR-2 - My favorite pocket knife. It's cheap, it's always sharp, it's made of stainless steel, and it has the coolest auto-locking mechanism. This knife (with one of their "ultrasharp" series replacement blades) cut the foam.
  15. New Trent IMP52D USB Battery Pack - For some reason this has a (useless) LED flashlight and a red laser pointer. 5200MAh. I've recently purchased a slightly smaller RAVPower 5600MAh unit to replace it.
  16. Schweitzer SEL 2924 Bluetooth Serial Adapter - I like this one better than my other Bluetooth serial adapter because this one runs on AAA batteries (like the other stuff here), charges AAA batteries (when the mouse batteries die, I swap them into this guy for charging), has dip switches for configuring baud rate, and, while the threaded hardware is backwards (thumbscrews), the DE-9 connector has the correct gender for my application. The charge port is micro-usb. The folks at SEL are nice, but a little weird about documentation. They seem to be afraid that terrorists will be downloading product manuals. I tried, failed to take it apart. SEL engineering reports that the case halves have ultrasonic welded seams :(
  17. Apple Thunderbolt to Gigabit Ethernet adapters - Two of them. Lots of NICs supports packet capture for diagnostic and performance purposes.
  18. Tiny USB flash drive
  19. MicroSD reader
  20. Apple Lightning to MicroUSB adapter
What do you carry around? Is there anything I should consider adding?

The mouse gets used so frequently that I may relegate it to a side pocket in my backpack. This would save me the hassle of pulling out the case so often, and free up some real estate. On the other hand, I admit that I get some satisfaction from plunking this case down on a conference table, because people always want to check it out.