SU_PYROW

Surf

03-15-2000 By: SU_PYROW

surf is a small script to help automate wireless WEP connections, knowing exactly what is being done

You must fill in the variables yourself!

#!/bin/sh
#
#
dev="used when running 'surf'"
VERSION=.1
WLAN=$1
HIGHPOWER= #0
TXPOWER= #20
BOND="only used when cards are already bonded"
MAC=00:11:22:44:33:55 # new mac address
ESSID=10FX03028904
AP=00:11:22:33:44:55 #Access Point (wifi router)
KEY=0000000000 # use "off" for 'none'
NTP=north-america.pool.ntp.org
RATE=auto
DHCP=1
#
STATIC_IP=192.168.1.18
GW=192.168.1.1
#
GREP="/bin/grep"
IFCONFIG="/sbin/ifconfig"
IWCONFIG="/sbin/iwconfig"
DHCLIENT="/sbin/dhclient"
NTPDATE="/usr/sbin/ntpdate"
MODPROBE="/sbin/modprobe"
MACCHANGER="/usr/local/bin/macchanger"
RMMOD="/sbin/rmmod"
IWPRIV="/sbin/iwpriv"
#
# Module is the wifi driver, rtl8187, rt2500pci, etc... whatever driver you
#need to run.#
MODULE=rt2500pci
#
usage()
{
	echo "Usage:	surf [options] device"
	echo "About:	surf is a small script to help automate wireless"
	echo "	connections, knowing exactly what is being done."
	echo "Requires: ifconfig, iwconfig, grep, dhclient, macchanger,"
	echo "  ntpdate, iwpriv"
	echo ""
	echo "surf, as of now does not handle WPA/WPA2 connections as of yet,"
	echo "  however can be easily modified to do so."
	echo ""
	echo "--help			Print this help"
	echo "--version		Print version and exit"
	echo "--show			Print current settings"
	echo ""
	echo "If you find a bug let me know."
exit 0
}
#
version()
{
	echo "surf-$VERSION"
	echo "Written by SU_PyRoW"
	echo ""
	echo "Copyright (C) 2000."
exit 0
}
#
show()
{
	echo "These are the defaults to be used unless changed:"
	echo ""
	echo "Wireless lan device:			$dev"
	echo "Bonded devices:				$BOND"
	echo "MAC address to be set:			$MAC"
	echo "ESSID:					$ESSID"
	echo "Access Point:				$AP"
	echo "Encryption WEP key:			$KEY"
	echo "Network Time Protocol server:		$NTP"
	echo "Wireless device rate of speed:		$RATE"
	echo "DHCP: on=1 off=0:			$DHCP"
	echo "Static IP; applies if DHCP is off:	$STATIC_IP"
	echo "Gateway; applies if DHCP is off:	$GW"
exit 0
}
#
if [ $# -lt 1 ]; then
	echo "surf: option '$1' not recognized."
	echo "surf: '--help' gives usage information"
exit 1
elif [ "$1" = "--version" ]; then
	version
exit 0
elif [ "$1" = "--show" ]; then
	show
exit 0
elif [ "$1" = "--help" ]; then
	usage
exit 0

elif [ $EUID -ne 0 ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
#
$IFCONFIG $1 | wc -l | $GREP 0 2>&1
#
if [ $? = 0 ]; then
	echo "$1 Does not appear to be on this system"
	exit 0
fi
#
if [ $? = 0 ];
	shift 1
	then
	echo "Shutting down $WLAN ...";
	echo "Device $WLAN Restarting/Leaving Promiscuous Mode";
	$IFCONFIG $WLAN down;
	$RMMOD $MODULE;
	$MODPROBE $MODULE;
	echo "Shutting down DHCP Client";
	killall $DHCLIENT
	echo "Resetting ESSID"
	$IWCONFIG $WLAN essid xoxoxoxoxox key off ap 00:00:00:00:00:00;
	echo "Starting Network";
	echo "Change MAC on $WLAN";
#
	$MACCHANGER --mac $MAC $WLAN;
	echo "Device $WLAN Restarted/Entering Managed Mode";
	sleep 1;
	$IWCONFIG $WLAN mode managed;
	echo "Stopping DHCP Client if running...";
	killall $DHCLIENT;
	sleep 1;
	echo "OK.";
	echo "Restarting device $WLAN configured for 1st network:";
#
	$IFCONFIG $WLAN up;
 	$IWPRIV $WLAN highpower $HIGHPOWER;
	$IWCONFIG $WLAN txpower $TXPOWER;
	$IWCONFIG $WLAN rate $RATE;
	$IWCONFIG $WLAN essid $ESSID key $KEY ap $AP;
#
if test $DHCP -eq 1
then
	echo "Starting DHCP Client..." ;
	$DHCLIENT $WLAN
	else
	echo "Setting Static IP: $STATIC_IP" ;
	$IFCONFIG $WLAN $STATIC_IP ;
	route add default gw $GW
fi
echo "Wireless network configured!";
sleep 1;
	echo ""
	echo "Updating Time:";
	$NTPDATE $NTP
fi

This document was last modified on: 133120 13:08:26 UTC