Tag Archives: connection

NCOER Spreadsheet

Last week, I complained about how bulky VBA (Visual Basic for Applications) can be.  My current project is to create a spreadsheet to keep track of upcoming NCOERs.  This is an easy task in anything but the most used and abused application the admin personnel in the Army use, Microsoft Excel.  Now, the data is easy enough to pull once you get an SSL connection with this website (to access you need to use an AKO Username/Password.)  The Interactive Web Response System will allow you to pull data on any past, due or current NCOERS (Evaluations).  This is great as I can track our evaluations as they move up the chain and will see when they are late.  Unfortunately, the web designers have only sorted the information by last name.

So, my basic program is complete.  I can make a connection (fortunately, MSXML6.0 makes an easy post request to an SSL website… something that if using Python, is not an easy task.)  It would appear that it is utilizing Internet Explorer’s library for the connection.  Once the connection is made and the data is loaded, then I parse.  Here is where VBA gets bulky.  Fortunately, I can use a reference to VBScript’s RegEx object, but it is far from being as complete as say, any other regex engine in any other language.  On top of that, parsing text through splits and such is an amazing pain.  Here’s an example.

Python:

import re
test = 'A simple "test of the languages" will show how bad VBA is!'
a = re.findall(re.compile(r'".*"',re.I),test)
print "Result = %s" % a[0]
## Result = "test of the languages"

VBA:

Private Sub CommandButton1_Click()
    ' must include Microsoft VBScript Regular Expressions 5.5 in references
    Dim re As New RegExp
    Dim testing As Variant
    Dim test As String
    ' to escape quotes "" can be used or chr(34).
    ' unbelievably, chr(34) is easier to read than ""
    test = "A simple " & Chr(34) & "test of the languages" & Chr(34) & " will show how bad VBA is!"
    re.Pattern = Chr(34) & ".*" & Chr(34)
    re.IgnoreCase = True
    Set testing = re.Execute(test)
    Range("A1").Value = "Result = " & testing(0)
    ' Result = "test of the languages" in "A1"
End Sub

See the difference?  I know it’s pretty close but keep in mind, this is a single line of text.  Multiple lines, large text files, etc. can be horrendous.  What in the world is left, mid and right anyhow?  I know 90% of this is that I refuse to touch this language if I can avoid it but still, this is ridiculous!!

Linux bash script for wifi.

When starting with Backtrack4, I compiled and installed the Broadcom wl driver for my laptop’s wifi. The unfortunate thing was that I got very frustrated because the default connection manager, wicd was getting confused when I would go to a network other than the one I initially connected to after boot-up. Shortly after that, Ubuntu 9.10 was experiencing the same difficulty after upgrading the kernel. So to work around using a network manager, I created a quick script to use.

In this script, you can see that you can pass a variable for your network name and key in the same format as you would normally. This was a fun script as it could easily be adapted as it’s own network manager, even with a little more work, you could have it in the tray, it’s own gui, etc. It’s nothing more than the commands typically used to connect on wifi but it just automated the process. I then went and created a child script for my most used networks, and after placing these in my bin, I actually have started to prefer this method.

Here’s the script:

#!/bin/bash

# die with honor
function usage() {
	echo "usage: ./connectWifi \"<essid>\" [key]"
	echo "       *key in ascii prefaces s:[key]"
	echo
	exit 1
}

# killed in disgrace
function die() {
	echo
	echo "   [*] ERROR: $1..."
	echo
	exit 1
}

# check for essid
if [[ $1 ]]; then
	# setup
	echo "Starting..."
	ifconfig eth1 down
	dhclient -r eth1 -q
	echo " -Previous connection dropped."
	ifconfig eth1 up
	iwconfig eth1 essid "$1"
	echo " -ESSID Set to $1."
	# check for key
	if [[ $2 ]]; then
		iwconfig eth1 key $2
		echo " -Key set to $2."
	fi
	# connect
	iwconfig eth1 mode Managed
	echo " -Connecting..."
	echo
	dhclient eth1
	# announce success
	if [[ $? -eq 0 ]]; then
		echo
		echo "Successfully connected to $1!"
		echo
		exit 0
	fi

else
	# no variables
	usage
fi

# declare failure
die "Failed to connect to $1."

This can serve as a good example of both the commands in connecting to wifi and an introduction to bash scripting. Please comment on the code and offer any suggestions you may have!