UPDATE: Modern Bash Wifi Connection Script for Linux; goodbye network manager

An update to a previous post.  This script has some more command line features, such as calling up previous saved sessions credentials from the command line and improved error handling.  Completely run from the command line.

View it here: http://pastebin.com/J229Gc1t

or below.


#!/bin/bash

# http://pastebin.com/J229Gc1t
# 12/06/2013
# This script attempts to semi-automate the wifi connection process from
# the command line.
# It is intended to be used on a headless machine without the
# requirement of typing several commands for a connection.
# The script stores previous connection credentials in PLAINTEXT as
# *.wpa files in the executed directory and in /etc/wpasupplicant.conf.
# These .wpa files are used to connect to several different ap using
# previously stored info.
# Probably a good idea to stop and other network managing software while
# running this script, also in testing wpa_supplicant does a pretty good
# job of re-connecting a disassociated link automatically.
#
# Mainly created from a combination of scripts taken from theses two
# sources:
# http://www.backtrack-linux.org/forums/archive/index.php/t-3367.html
# AND
# http://www.linuxquestions.org/questions/linux-general-1/wifi-connect\
# -script-tested-in-ubuntu-772646/
#
# old version1 http://pastebin.com/Pa90HBiU 01/06/2013
# very simple first version
# old version2 http://pastebin.com/FzJnv5Nk 02/06/2013
# minor additions
# old version3 http://pastebin.com/3mu1XT5Y 08/06/2013
# included ability to call up previous saved files from
# command line. Some checking of command line parameters and
# checking for empty saved files
# current version
# Added exit retrurn values
#
# Copy, Distribute and Modify Freely.
#

if [ -z "$1" ]; then
printf "Usage: $0 -i [interface] OR AND -f [SAVED_FILE.wpa]\n"
exit 1
fi

while getopts "i:f:" opt
do
case $opt in
i ) INT=${OPTARG};;
f ) ITEM=${OPTARG};;
\?) printf "Usage: $0 -i [interface] OR AND -f [SAVED_FILE.wpa]\n"
exit 1;;
* ) printf "Usage: $0 -i [interface] OR AND -f [SAVED_FILE.wpa]\n"
exit 1;;
esac
done

#
# check if root
#
if [ "$(id -u)" != "0" ]; then
printf "This script must be run as root\n" 1>&2
exit 1
fi

#
# check if interface is entered as command line argument
#
if [ -z "$INT" ]; then
printf "Usage: $0 -i [interface] OR AND -f [SAVED_FILE.wpa]\n"
exit 1
fi

#
# Search for previous saved config files
#
function read_saved (){
#
# Search or uses for previous wpa configuration files
# Checks if command line argument -f [SAVED_FILE.wpa] is greater than zero length and exists
# before writing the configiuration to wpa_supplicant.conf. Otherwise create a new
# configuration.
#
if [ -n "$ITEM" ]; then
if [ -s "$ITEM" ]; then
printf "File $ITEM exists, proceeding to connect\n"
write_conf $ITEM
else printf "File $ITEM is invalid or does not exist, proceeding to create a new configuration\n"
conf_create
fi
fi
#
# Save and change IFS so spaces in file names are not interpreted as
# separate lines in the array
#
OLDIFS=$IFS
IFS=$'\n'

#
# Read all file names into an array
# ref:http://www.cyberciti.biz/tips/handling-filenames-with-spaces\
# -in-bash.html
#
# " -printf '%f\n' " removes path info from outputs
#
# ref:http://serverfault.com/questions/354403/remove-path-from-find\
# -command-output
#
SAVED_LIST=($(find . -type f -name "*.wpa" -printf '%f\n'))

#
# restore ifs
#
IFS=$OLDIFS

#
# Tests for number of saved wifi connections, if none exit
#
if [ -z "${SAVED_LIST[0]}" ]; then
printf "There are no previous saved wifi connections\n"
#
# Create new connection
#
conf_create
fi

#
#PS3 Sets the prompt for the select statement below
#
PS3="Choose a previously saved wifi connection or 's' to skip: "

#
#Select one of the previous saved configurations to connect with or quit
#
select ITEM in "${SAVED_LIST[@]}"; do
#
# Quit if selected number does not exist or alpha in entered
#
if [ -z "$ITEM" ] ; then
printf "Skipping\n\n"
conf_create
fi
#
# Quick check if file is greater than zero length and exists
#
if [ -s "$ITEM" ]; then
printf "File $ITEM exists, proceeding to connect\n"
write_conf "$ITEM"
else printf "File $ITEM is invalid or does not exist, proceeding to create a new configuration\n"
conf_create
fi
done
}

function conf_create (){
#
# Scans for wifi connections & isolates wifi AP name
#
eval LIST=( $(iwlist $INT scan 2>/dev/null | awk -F":" '/ESSID/{print $2}') )

#
#PS3 Sets the prompt for the select statement below
#
PS3="Choose wifi connection or 'q' to quit: "

#
# Tests for number of wifi connections, exits if none
#
if [ -z "${LIST[0]}" ]; then
printf "No available wifi connection using $INT\n"
exit 1
fi

#
# Select from a LIST of scanned connections
#
select ITEM in "${LIST[@]}"; do

#
# Quit if selected number does not exist or alpha in entered
#
if [ -z "$ITEM" ] ; then
printf "Exiting\n"
exit 0
fi

#
# Get user input for passphrase no need to escape spaces
#
printf "Enter the passphrase for $ITEM?\n"
read "PASSPHRASE"

#
# Append the ITEM variable (ESSID) to .wpa to make a filename
# for saved configs
#
FILENAME=$ITEM".wpa"

#
# Run wpa_passphrase to generate a file for wpa_supplicant to
# use, store it locally and in etc/wpa_supplicant.conf
#
printf "Running wpa_passphrase\n"
wpa_passphrase "$ITEM" "$PASSPHRASE" > "$FILENAME" | xargs
#
# Jump to write_conf function, append configuration filename
# to ITEM varibale
#
ITEM="$FILENAME"
write_conf
done
}

function write_conf (){
#
# Copy local wpa_supplicant file to etc/wpa_supplicant.conf
#
printf "Writing new configuration file using $ITEM\n"
cat "$ITEM">/etc/wpa_supplicant.conf | xargs
#
# Jump to connect function, pass on the ESSID variable for connection
#
connect "$ITEM"
}

function connect (){
printf "Connecting using file $*\n"

#
# Capture incoming argument
#
ESSID=$*

#
# Kill previous instances of wpa_supplicant to stop other instances
# wpa_supplicant fighting several different AP's
# Kill based on
# ref: http://thegeekstuff.com/2011/10/grep-or-and-not-operators
# and
# http://stackoverflow.com/questions/3510673/find-and-kill-a-\
# process-in-one-line-using-bash-and-regex
#
# Release dhcp ip's and bring down the interface
#
kill $(ps aux | grep -E '[w]pa_supplicant.*\'$INT'' | awk '{print $2}') 2>/dev/null | xargs
dhclient $INT -r
ifconfig $INT down

#
# Assign new credentials to interface
#
iwconfig $INT mode managed essid "$ESSID"
printf "Configured interface $INT; Credential file is $ESSID\n"
ifconfig $INT up
printf "Interface $INT is up\n"
wpa_supplicant -B -Dwext -i$INT -c/etc/wpa_supplicant.conf 2>/dev/null | xargs
printf "wpa_supplicant running, sleeping for 15...\n"

#
# Wait to connect before asking for a ip address
#
sleep 15
printf "Running dhclient\n"
dhclient $INT

#
# Show current ip for interface
#
ifconfig $INT | grep inet
exit 0
}

function clean_slate (){
#
# Optional Clean Slate commands, it is recommended that you perform
# a "airmon-ng check kill" to ensure that any other network managers
# do not interfere with the connection process
#

printf "It is recommended that you perform a \"airmon-ng check kill\" once to ensure that any other network managers do not interfere with the connection process\n\n"

#
# Untested, airmon-ng check kill works better here
#
# service network-manager stop 2>/dev/null >/dev/null
# service avahi-daemon stop 2>/dev/null >/dev/null
# sleep 10
# killall wpa_supplicant 2>/dev/null
# ifconfig $INT up
}

#
# Start here
#
clean_slate
read_saved

exit 0

WindyCityTech Blogger
WindyWindyCityTech WordPress

Firefox Progress of Ongoing Downloads Revert to old style

Once again, like the pdf thing that Mozilla did a while back.  The new download window:

  • Takes up a whole tab
  • Cannot be resized
  • Blocks any bookmarks on your bookmarks toolbar

Unfortunately the only fix to the old style, aka, before FF21 is to do two things:

  • Revert from private browsing (Preferences > Privacy > History > Custom Settings)
  •  Open about:config and toogle browser.download.useToolkitUI to TRUE
Un-tick private browsing :(

The analogy is that private browsing does not remember any downloading history, so the browser.download.useToolkitUI change will not show any downloads in the old style list.

WindyCityTech Blogger
WindyWindyCityTech WordPress

Ghostery, it’s better than nothing or is it

Ghostery is probably better than nothing but several facts exist.

  1. Ghostery filters are updated by Ghostery company Evidon, Inc themselves.  This feel a little closed source for me, it means that they could white list some trackers if they felt like. 
  2. Ghostery is closed source, they claim that you can look thought their xpi package to see what is inside it, but that is like M$ asking their someone to look into their exe file to see what is inside.
  3. You may not disassemble or reverse engineer Ghostery for any purpose other than reviewing the code for personal edification, so much for trying to be open source soon…
  4. Participating in the GhostRank program (default)  This is a no-brainer.
  5. Merger, Sale, or Reorganization of Evidon
    If Evidon should ever file for bankruptcy, or have its assets sold to or merged with another entity, information Evidon receives from you, from the Website, is an Evidon asset and may be transferred.
  6. And this: http://venturebeat.com/2012/07/31/ghostery-a-web-tracking-blocker-that-actually-helps-the-ad-industry/

    “After all, the thinking goes, many ad networks sell their advertisements via real-time bidding, so they often lack a clear idea of where their tags are appearing. In short, online ad networks are just as hungry for information about web users as they are for data about themselves. Ghostery gives them that information.”
    “This gives Evidon a clear target market and even clearer plan of attack: Use Ghostery users to build the tracker database, then turn around and license the data to ad networks who can use the data to bolster their own efforts.”

So in essence, the use of Ghostery is helping ads networks find better and more covert ways to track you online presence and these guys are using you to make a nice little database….
I’m not bothering to go any further and look at the chatter on the wire, do not install it.  Stick with adblock-lite +Fanboy Adblock List + Tracking List + Annoyance Block List.

If you still don’t get it, too bad your a sad panda.

WindyCityTech Blogger
WindyWindyCityTech WordPress

Quick install of Linux firmware htc_9271.fw for TP-LINK TLWN422G USB Wireless

Download firmware from here or search for newer.
http://wireless.kernel.org/download/htc_fw/1.3/htc_9271.fw

sudo cp htc_9271.fw /lib/firmware/.

Plug in device and do a dmesg to see if firmware is loaded.

Works great on airodump-ng, injection is super.\

lsusb

Bus 001 Device 004: ID 0cf3:1006 Atheros Communications, Inc. TP-Link TL-WN322G v3 / TL-WN422G v2 802.11g [Atheros AR9271]

Don’t waste time trying to compile anything else.

WindyCityTech Blogger
WindyWindyCityTech WordPress

Modern Bash Wifi Connection Script for Linux; goodbye network manager

This script attempts to semi-automate the wifi connection process from
the command line.  It is intended to be used on a headless / GUI-less machine without the
requirement of typing several commands for a connection.  For instance a Raspberry PI.

It works reasonably well for most applications and can handle ESSID’s / passwords with spaces.

Storage of previous connection credentials is in PLAINTEXT as [ESSID].wpa files in the executed directory and in /etc/wpasupplicant.conf.
These .wpa files are used to connect to several different AP’s using previously stored info.
Probably a real good idea to stop and other network managing software while running this script, for instance running “airmon-ng check kill” will do a good job.
Also in testing wpa_supplicant does a pretty good job of re-connecting a disassociated link automatically.

Operation is simple.  In the case with Debian it is:
sudo ./connect.sh wlan0

Mainly created from a combination of scripts taken from theses two
sources:
http://www.backtrack-linux.org/forums/archive/index.php/t-3367.html
AND
http://www.linuxquestions.org/questions/linux-general-1/wifi-connect-script-tested-in-ubuntu-772646/

Feel free to comment or send improvements.

Download from http://pastebin.com/FzJnv5Nk
or below.

#!/bin/bash

# http://pastebin.com/Pa90HBiU
# 01/06/2013
# This script attempts to semi-automate the wifi connection process from
# the command line.
# It is intended to be used on a headless machine without the
# requirement of typing several commands for a connection.
# The script stores previous connection credentials in PLAINTEXT as
# *.wpa files in the executed directory and in /etc/wpasupplicant.conf.
# These .wpa files are used to connect to several different ap using
# previously stored info.
# Probably a good idea to stop and other network managing software while
# running this script, also in testing wpa_supplicant does a pretty good
# job of re-connecting a disassociated link automatically.
#
# Mainly created from a combination of scripts taken from theses two
# sources:
# http://www.backtrack-linux.org/forums/archive/index.php/t-3367.html
# AND
# http://www.linuxquestions.org/questions/linux-general-1/wifi-connect\
# -script-tested-in-ubuntu-772646/
#
# old version http://pastebin.com/Pa90HBiU 01/06/2013
#
# Copy, Distribute and Modify Freely.
#

INT=$1

if [ -z "$1" ]; then
printf "Usage: $0 [interface]\n"
exit
fi

if [ "$(id -u)" != "0" ]; then
printf "This script must be run as root\n" 1>&2
exit
fi

#
# Search for previous saved config files
#
function read_saved {
#
# Search for previous wpa configuration files.
#

#
# Save and change IFS so spaces in file names are not interpreted as
# separate lines in the array
#
OLDIFS=$IFS
IFS=$'\n'

#
# Read all file names into an array
# ref:http://www.cyberciti.biz/tips/handling-filenames-with-spaces\
# -in-bash.html
#
# " -printf '%f\n' " removes path info from outputs
#
# ref:http://serverfault.com/questions/354403/remove-path-from-find\
# -command-output
#
SAVED_LIST=($(find . -type f -name "*.wpa" -printf '%f\n'))

#
# restore ifs
#
IFS=$OLDIFS

#
# Tests for number of saved wifi connections, if none exit
#
if [ -z "${SAVED_LIST[0]}" ]; then
printf "There are no previous saved wifi connections\n\n"
#
# Create new connection
#
conf_create
fi

#
#PS3 Sets the prompt for the select statement below
#
PS3="Choose a previously saved wifi connection or 's' to skip: "

#
#Select one of the previous saved configurations to connect with or quit
#
select ITEM in "${SAVED_LIST[@]}"; do
#
# Quit if selected number does not exist or alpha in entered
#
if [ -z "$ITEM" ] ; then
printf "Skipping\n"
conf_create
fi

printf "$ITEM is selected\n"
cat "$ITEM">/etc/wpa_supplicant.conf | xargs
connect "$ITEM"
done
}

function conf_create (){
#
# Scans for wifi connections & isolates wifi AP name
#
eval LIST=( $(iwlist $INT scan 2>/dev/null | awk -F":" '/ESSID/{print $2}') )

#
#PS3 Sets the prompt for the select statement below
#
PS3="Choose wifi connection or 'q' to quit: "

#
# Tests for number of wifi connections, exits if none
#
if [ -z "${LIST[0]}" ]; then
printf "No available wifi connection using $INT\n"
exit
fi

#
# Select from a LIST of scanned connections
#
select ITEM in "${LIST[@]}"; do
ifconfig $INT | grep inet

#
# Quit if selected number does not exist or alpha in entered
#
if [ -z "$ITEM" ] ; then
printf "Exiting\n"
exit
fi

#
# Get user input for passphrase no need to escape spaces
#
printf "Enter the passphrase for $ITEM?\n"
read "PASSPHRASE"

#
# Append the ITEM variable (ESSID) to .wpa to make a filename
# for saved configs
#
FILENAME=$ITEM".wpa"

#
# Run wpa_passphrase to generate a file for wpa_supplicant to
# use, store it locally and in etc/wpa_supplicant.conf
#
printf "Running wpa_passphrase\n"
wpa_passphrase "$ITEM" "$PASSPHRASE" > "$FILENAME" | xargs
cat "$FILENAME">/etc/wpa_supplicant.conf | xargs
printf "Creating new configuration using $ITEM\n"

#
# Jump to connect function, pass on the ESSID variable for connection
#
connect $ITEM
done
}

function connect (){
printf "Connecting using file $*\n"

#
# Capture incoming argument
#
ESSID=$*

#
# Kill previous instances of wpa_supplicant to stop other instances
# wpa_supplicant fighting several different AP's
# Kill based on
# ref: http://thegeekstuff.com/2011/10/grep-or-and-not-operators
# and
# http://stackoverflow.com/questions/3510673/find-and-kill-a-\
# process-in-one-line-using-bash-and-regex
#
# Release dhcp ip's and bring down the interface
#
kill $(ps aux | grep -E '[w]pa_supplicant.*\'$INT'' | awk '{print $2}') 2>/dev/null | xargs
dhclient $INT -r
ifconfig $INT down

#
# Assign new credentials to interface
#
iwconfig $INT mode managed essid "$ESSID"
printf "Configured interface $INT; ESSID is $ESSID\n"
ifconfig $INT up
printf "Interface $INT is up\n"
wpa_supplicant -B -Dwext -i$INT -c/etc/wpa_supplicant.conf 2>/dev/null | xargs
printf "wpa_supplicant running, sleeping for 15...\n"

#
# Wait to connect before asking for a ip address
#
sleep 15
printf "Running dhclient\n"
dhclient $INT

#
# Show current ip for interface
#
ifconfig $INT | grep inet
exit
}

function clean_slate (){
#
# Optional Clean Slate commands, it is recommended that you perform
# a "airmon-ng check kill" to ensure that any other network managers
# do not intefere with the connection process
#

printf "It is recommended that you perform a \"airmon-ng check kill\" once to ensure that any other network managers do not interfere with the connection process\n"

#
# Untested, airmon-ng check kill works better here
#
# service network-manager stop 2>/dev/null >/dev/null
# service avahi-daemon stop 2>/dev/null >/dev/null
# sleep 10
# killall wpa_supplicant 2>/dev/null
# ifconfig $INT up
}

#
# Start here
#
clean_slate
read_saved

exit

WindyCityTech Blogger
WindyWindyCityTech WordPress

Using a Common mode Choke (differential) as a joule thief transformer (working)

Almost any switch mode power supply has one of these chokes for noise suppression.  The type pictured below is the type that has been tested working.

The prewound choke Coil has even windings on both sides and uses many turns of thick wire around a ferrite core.
Using the standard Joule Thief configuration, it has been tested with a BD139 transistor, 1.4K Ohm Feedback Resistor and a Blue LED.
Starts up easily at 0.6V DC. and is much brighter than the standard joule thief at 1.5 Volts.

WindyCityTech Blogger
WindyWindyCityTech WordPress