Results 1 to 3 of 3

Thread: iwconfig auto script

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Location
    Carmel, IN USA
    Posts
    36

    Default iwconfig auto script

    I wrote because I was sick an tired of typing out all the commands. Any suggestions on how to make it better or more streamline? Only my second bash script so please be gentle LOL.

    you can save it as whatever but make sure you do a chmod a+x ./iwconfig.sh
    Code:
    #!/bin/bash
    
    # Colors
    txtblk='\e[0;30m' # Black - Regular
    txtred='\e[0;31m' # Red
    txtgrn='\e[0;32m' # Green
    txtylw='\e[0;33m' # Yellow
    txtblu='\e[0;34m' # Blue
    txtpur='\e[0;35m' # Purple
    txtcyn='\e[0;36m' # Cyan
    txtwht='\e[0;37m' # White
    bldblk='\e[1;30m' # Black - Bold
    bldred='\e[1;31m' # Red
    bldgrn='\e[1;32m' # Green
    bldylw='\e[1;33m' # Yellow
    bldblu='\e[1;34m' # Blue
    bldpur='\e[1;35m' # Purple
    bldcyn='\e[1;36m' # Cyan
    bldwht='\e[1;37m' # White
    unkblk='\e[4;30m' # Black - Underline
    undred='\e[4;31m' # Red
    undgrn='\e[4;32m' # Green
    undylw='\e[4;33m' # Yellow
    undblu='\e[4;34m' # Blue
    undpur='\e[4;35m' # Purple
    undcyn='\e[4;36m' # Cyan
    undwht='\e[4;37m' # White
    bakblk='\e[40m'   # Black - Background
    bakred='\e[41m'   # Red
    badgrn='\e[42m'   # Green
    bakylw='\e[43m'   # Yellow
    bakblu='\e[44m'   # Blue
    bakpur='\e[45m'   # Purple
    bakcyn='\e[46m'   # Cyan
    bakwht='\e[47m'   # White
    txtrst='\e[0m'    # Text Reset
    
    # End of colors
    
    info() {
    	clear
    	sleep 2
    	echo -e "${bldgrn}"
    	echo -e ".------------------------------------------------------."
    	echo -e ".        Auto iwconfig Script                          ."
    	echo -e ".        Usage: ./iwconfig.sh <i> <e> <c> <k> <tx>     ."
    	echo -e ".        <i> : interface to use                        ."
    	echo -e ".        <e> : essid to connect to                     ."
    	echo -e ".        <c> : channel to use                          ."
    	echo -e ".        <k> : key to use                              ."
    	echo -e ".        <tx> : txpower                                ."
    	echo -e "'------------------------------------------------------'"
    	echo -e "${txtrst}"
    	sleep 2
    }
    
    info
    
    config() {
    	if [[ $1 ]]; then echo -e "${bldylw}interface set:" $1 ; else echo -e "${txtred}interface not set"; exit 0; fi
    	if [[ $2 ]]; then echo -e "${bldylw}essid set:" $2 ; else echo -e "${txtred}essid not set"; exit 0; fi
    	if [[ $3 ]]; then echo -e "${bldylw}channel set:" $3 ; else echo -e "${txtred}channel not set"; exit 0; fi
    	if [[ $4 ]]; then echo -e "${bldylw}key set:" $4 ; else echo -e "${txtred}key not set"; exit 0; fi
    	if [[ $5 ]]; then echo -e "${bldylw}txpower set:" $5 ; else echo -e "${txtred}txpower not set"; exit 0; fi
    	echo -e "${txtrst}"
    	sleep 2
    }
    
    config $1 $2 $3 $4 $5
    
    execute () {
    	echo -e "${txtpur}"
    	echo -e "Taking down interface : $1"
    	ifconfig $1 down
    	sleep 5
    	echo -e "Setting essid for interface : $1 to $2"
    	iwconfig $1 essid $2
    	sleep 2
    	echo -e "Setting channel for interface : $1 to channel $3"
    	iwconfig $1 channel $3
    	sleep 2
    	echo -e "Setting key for interface : $1 to $4"
    	iwconfig $1 enc $4
    	sleep 2
    	echo -e "Setting txpower for interface : $1 to $5"
    	iwconfig $1 txpower $5
    	sleep 2
    	echo -e "Bringing up interface : $1"
    	ifconfig $1 up
    	sleep 5
    	echo -e "${txtrst}"
    }
    
    if [[ $1 ]] && [[ $2 ]] && [[ $3 ]] && [[ $4 ]] && [[ $5 ]]; then execute $1 $2 $3 $4 $5; fi
    edited to reflect a very good point brought up by Archangel-Amael.... Thanks LOL
    Last edited by ondrovic; 06-21-2010 at 06:01 PM. Reason: changed file name

  2. #2
    Super Moderator Archangel-Amael's Avatar
    Join Date
    Jan 2010
    Location
    Somewhere
    Posts
    8,012

    Default Re: iwconfig auto script

    Well if I save it as whatever I want and then run it with that name and flags then it will print out the following usage:
    Usage: ./iwconfig.sh <i> <e> <c> <k> <tx>
    iwconfig.sh being the name you intended maybe?
    Small fish for some but may be a big stumbling block for others.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Location
    Carmel, IN USA
    Posts
    36

    Default Re: iwconfig auto script

    here is an update to the script since I ran into issues I added the mode : managed and dhclient

    Code:
    #!/bin/bash
    
    # Colors
    txtblk='\e[0;30m' # Black - Regular
    txtred='\e[0;31m' # Red
    txtgrn='\e[0;32m' # Green
    txtylw='\e[0;33m' # Yellow
    txtblu='\e[0;34m' # Blue
    txtpur='\e[0;35m' # Purple
    txtcyn='\e[0;36m' # Cyan
    txtwht='\e[0;37m' # White
    bldblk='\e[1;30m' # Black - Bold
    bldred='\e[1;31m' # Red
    bldgrn='\e[1;32m' # Green
    bldylw='\e[1;33m' # Yellow
    bldblu='\e[1;34m' # Blue
    bldpur='\e[1;35m' # Purple
    bldcyn='\e[1;36m' # Cyan
    bldwht='\e[1;37m' # White
    unkblk='\e[4;30m' # Black - Underline
    undred='\e[4;31m' # Red
    undgrn='\e[4;32m' # Green
    undylw='\e[4;33m' # Yellow
    undblu='\e[4;34m' # Blue
    undpur='\e[4;35m' # Purple
    undcyn='\e[4;36m' # Cyan
    undwht='\e[4;37m' # White
    bakblk='\e[40m'   # Black - Background
    bakred='\e[41m'   # Red
    badgrn='\e[42m'   # Green
    bakylw='\e[43m'   # Yellow
    bakblu='\e[44m'   # Blue
    bakpur='\e[45m'   # Purple
    bakcyn='\e[46m'   # Cyan
    bakwht='\e[47m'   # White
    txtrst='\e[0m'    # Text Reset
    
    # End of colors
    
    info() {
    	clear
    	sleep 2
    	echo -e "${bldgrn}"
    	echo -e ".------------------------------------------------------."
    	echo -e ".        Auto iwconfig Script                          ."
    	echo -e ".        Usage: ./iwconfig.sh <i> <e> <c> <k> <tx>     ."
    	echo -e ".        <i> : interface to use                        ."
    	echo -e ".        <e> : essid to connect to                     ."
    	echo -e ".        <c> : channel to use                          ."
    	echo -e ".        <k> : key to use                              ."
    	echo -e ".        <tx> : txpower                                ."
    	echo -e "'------------------------------------------------------'"
    	echo -e "${txtrst}"
    	sleep 2
    }
    
    info
    
    config() {
    	if [[ $1 ]]; then echo -e "${bldylw}interface set:" $1 ; else echo -e "${txtred}interface not set"; exit 0; fi
    	if [[ $2 ]]; then echo -e "${bldylw}essid set:" $2 ; else echo -e "${txtred}essid not set"; exit 0; fi
    	if [[ $3 ]]; then echo -e "${bldylw}channel set:" $3 ; else echo -e "${txtred}channel not set"; exit 0; fi
    	if [[ $4 ]]; then echo -e "${bldylw}key set:" $4 ; else echo -e "${txtred}key not set"; exit 0; fi
    	if [[ $5 ]]; then echo -e "${bldylw}txpower set:" $5 ; else echo -e "${txtred}txpower not set"; exit 0; fi
    	echo -e "${txtrst}"
    	sleep 2
    }
    
    config $1 $2 $3 $4 $5
    
    execute () {
    	echo -e "${txtpur}"
    	echo -e "Taking down interface : $1"
    	ifconfig $1 down
    	sleep 5
    	echo -e "Setting essid for interface : $1 to $2"
    	iwconfig $1 essid $2
    	sleep 2
    	echo -e "Setting channel for interface : $1 to channel $3"
    	iwconfig $1 channel $3
    	sleep 2
    	echo -e "Setting key for interface : $1 to $4"
    	iwconfig $1 enc $4
    	sleep 2
    	echo -e "Setting txpower for interface : $1 to $5"
    	iwconfig $1 txpower $5
    	sleep 2
    	echo -e "Setting mode to managed"
    	iwconfig $1 mode managed
    	sleep 2
    	echo -e "Bringing up interface : $1"
    	ifconfig $1 up
    	sleep 5
    	echo -e "Grabbing DHCP for interface : $1"
    	dhclient
    	echo -e "${txtrst}"
    }
    
    if [[ $1 ]] && [[ $2 ]] && [[ $3 ]] && [[ $4 ]] && [[ $5 ]]; then execute $1 $2 $3 $4 $5; fi

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2010, 11:40 PM
  2. Auto Migrate Script on Session Startup
    By ballzan in forum OLD Pentesting
    Replies: 5
    Last Post: 12-30-2009, 12:59 PM
  3. Auto WEP hack!! script
    By potter1984 in forum OLD Programming
    Replies: 5
    Last Post: 12-11-2008, 05:41 AM
  4. Help with auto-crack bash script
    By devilsson2010 in forum OLD BackTrack 3 Final
    Replies: 10
    Last Post: 10-30-2008, 08:55 AM
  5. Senao 2511 - Auto Script
    By imported_Speedy in forum OLD Newbie Area
    Replies: 0
    Last Post: 04-14-2007, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •