Crumpled Thoughts

October 30th, 2008

Windows PowerShell script for adding IP routes across a VPN

Posted by Chris in Technology, Windows

At my office we use a Microsoft ISA server for our firewall/VPN server. We have three discreet IP subnets within our private network. 192.168.5.0/24, 192.168.6.0/24, and 192.168.7/24. When I establish a VPN connection from the external network I get an IP address on the 192.168.6.0/24 network.

I have my VPN connection set up to not use the default gateway on the remote network. This prevents all of my internet traffic from being routed over the VPN while I am connected to it… the problem is that if I need to access a resource on the 192.168.5.0/24 or 192.168.7.0/24 networks, I have to manually add routes to them across the VPN.

The process was:

  • Find out what IP I was assigned on the VPN
  • Add an IP route to 192.168.5.0/24
  • Add an IP route to 192.168.7.0/24

If I was always assigned the same IP address on the VPN, I could have just put the commands in a batch file, but the IP address is dynamically assigned from a DHCP server and is always different than it was the last time. So this is what I used to do:

Old Way

That is a lot of typing! I’d been meaning to play around with Windows PowerShell anyhow, and decided to write a script to automate this task in PowerShell. This is what I came up with:

# vpn.ps1
#
# Add IP routes across a VPN via a DHCP assigned IP address
#
# Get the IP address of the VPN connection
$vpnip = ipconfig | findstr "192.168.6."
# If we don't have an IP address on the VPN, error and quit
if (!$vpnip) {
"You do not have an IP address on the VPN"
exit
}
# Trim any leading/trailing whitespace
$vpnip = $vpnip.Trim()
# Split the contents of $vpnip in to an array
$vpnip = $vpnip.Split(" ")
# Find out the depth of our IP address in the array
$bit = $vpnip.Length - 1
# Get out just our IP address on the VPN
$vpnip = $vpnip[$bit]
# Add whatever routes we need
route add 192.168.5.0 MASK 255.255.255.0 $vpnip
route add 192.168.7.0 MASK 255.255.255.0 $vpnip

I save the script as vpn.ps1 and put it in my “scripts” directory in my profile directory. Then I just put a shortcut on my desktop to powershell.exe C:\Users\chillman\scripts\vpn.ps1. Now I just connect to the vpn, launch my shortcut and I’m ready to go. Hopefully this will be useful to someone.

October 14th, 2008

My Official Prediction: Obama by a Landslide

Posted by Chris in Rant, Politics

I thought I’d make a prediction on how this race will end up, mostly to see how close I call it on November 5th.  I really think it’s shaping up to be a landslide.  The Obama campaign has been incredibly well organized and gaining ground in many swing states.  I gave Obama Florida because I think the Real Estate market (or crisis) there is giving him an edge over McCain.  I also gave Obama Colorado because I think there is a large group of people not being represented in the polls which tend to be more likely to support Obama (the younger voters).

Here’s my prediction.  Obama 320, McCain 218

This is how it breaks down:
landslide.png

Of course, there is a real possibility I’m completely wrong.  History will be the judge of that.

Make your own prediction with the CNN Electoral Map Calculator

October 8th, 2008

Dear CNN, this chart is useless.

Posted by Chris in Rant

Dear CNN,

I watched the 2nd presidential debate on your network last night. I found the following graph to be distracting and annoying. It really added nothing to the debate, except to make me wonder how people were going from ‘committed’ to ‘uncommitted’ so rapidly.

Most Useless Debate Chart

Please don’t use this in the coverage of the final debate, or I may be forced to watch it elsewhere.