Wireless connecting via CLI/Terminal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wireless connecting via CLI/Terminal
# 1  
Old 08-09-2016
Wireless connecting via CLI/Terminal

Do you use the CLI a lot and encounter new Wi-Fi sources, but don't want to/can't remember the commands to connect to the Internet?? I'm lazy. I mean, that's what scripting is for, right?? Efficiency means obtaining the maximum result with maximum laziness. I wrote this small script a while ago and have improved on it several times over the course of about 6 months. I personally like it a lot (obviously, I wrote it) and thought that others might also. So here it is. Also, any comments, ideas, changes, don't hesitate to post!! New ideas and ways of making things work better is always appreciated by everyone.

Code:
#!/bin/bash

 # Wi-Fi Commander, a lazy way to lazily connect to the WiFi

 # Updated: 15-8-16, Version 3.5

 # This script requires that nmcli, w3m, and w3m-img (if
 # you want to be able to see pictures), are all installed
 # on the computer running it

 # You must be a sudoer or root to use this script


DDG="www.duckduckgo.com"


test () {
echo; nmcli c show --active
echo; ping -q -c 3 $DDG
if [ "$?" -eq "0" ];
then echo; echo "Connection Successful."
else echo; echo "Connection Unsuccessful."
fi
}

discon () {
nmcli d disconnect wlan0
if [ "$?" -eq "10" ];
then echo; echo "wlan0 not found." ; echo; sleep .75; discon2
fi
}

discon2 () {
echo $(sudo ifconfig -a -s); echo; echo "Deactivate which connection??"; read dcon; nmcli d disconnect "$dcon"; echo
if [ "$?" -eq "10" ];
then echo; echo "Error with the Wi-Fi Adapter."
fi
}

interweb () {
echo; w3m $DDG
if [ "$?" -eq "0" ];
then echo " ";
else echo; echo "You are not connected to the internet."
fi
}


echo; echo "Welcome to Wi-Fi Commander."; sleep .75; echo

PS3="Wi-Fi Command: "
echo "Command Menu:"; echo; select command in "Activate Wireless device" "Scan for Wi-Fi" "Connect to new Wi-Fi" "Connect to a Saved Connection" "Test Connection" "Disconnect from Wi-Fi" "View Saved Connections" "View a Saved Connection's password" "Deactivate Wireless device" "Delete a Saved Connection" "Launch Browser (W3M)" "Exit"
do
case $command in
"Activate Wireless device") echo $(sudo ifconfig -a -s); echo; echo "Activate which device??"; echo; read device; sudo ifconfig "$device" up; echo;;
"Scan for Wi-Fi") echo; echo $(sudo iwlist scanning | grep -E "Quality|Signal level|Encryption key|ESSID"); echo;;
"Connect to new Wi-Fi") echo; echo "SSID:"; echo; read ssid; echo; echo "Key:"; echo; read -s passwd; sudo nmcli d wifi connect "$ssid" password "$passwd"; echo;;
"Connect to a Saved Connection") echo $(nmcli c); echo; echo "Connect to??"; echo; read ssid; nmcli c up id "$ssid";;
"Test Connection") test;;
"Disconnect from Wi-Fi") discon;;
"View Saved Connections") echo; echo $(nmcli c); echo;;
"View a Saved Connection's password") echo; echo $(nmcli c); echo; echo "Which Saved Connection??"; echo; read ssid; echo; sudo -k echo&&echo $(nmcli --show-secrets connection show "$ssid" | grep -E "802-11-wireless-security.psk:");;
"Deactivate Wireless device") echo $(sudo ifconfig -a -s); echo; echo "Deactivate which device??"; echo; read device; sudo ifconfig "$device" down; echo;;
"Delete a Saved Connection") echo; echo $(nmcli c); echo; echo "Delete which??"; echo; read ssid; nmcli c delete id "$ssid";;
"Launch Browser (W3M)") interweb;;
"Exit") echo; echo "Goodbye."; echo; exit;;
*) echo; echo "Command not recognised.";;
esac
echo; echo "Press Enter to view the Command Menu again."; echo
done


Last edited by Huitzilopochtli; 08-15-2016 at 02:50 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print Terminal Output Exactly how it Appears in the Terminal to a New Text File

Hello All, I have a text file containing output from a command that contains lots of escape/control characters that when viewed using vi or view, looks like jibberish. But when viewed using the cat command the output is formatted properly. Is there any way to take the output from the cat... (7 Replies)
Discussion started by: mrm5102
7 Replies

2. Shell Programming and Scripting

Cannot get terminal application to launch with a graphical launcher when successful in terminal

I have been having an extremely annoying problem. For the record, I am relatively new at this. I've only been working with unix-based OS's for roughly two years, mostly Xubuntu and some Kali. I am pretty familiar with the BASH language, as that's the default shell for debian. Now, I've made this... (16 Replies)
Discussion started by: Huitzilopochtli
16 Replies

3. UNIX for Dummies Questions & Answers

Does DOS has a terminal or pseudo terminal?

I am wondering if the DOS console works like the unix terminal? (1 Reply)
Discussion started by: vistastar
1 Replies

4. Programming

terminal IO for CLI devlopment

Hi all, Am trying to develop CLI kind of program which does a telcom switch configuration . I have to provide a terminal and a prompt to user for that I did following: static struct termios old_term; struct termios new_term; tcgetattr(STDIN_FILENO, &old_term); new_term = old_term; ... (3 Replies)
Discussion started by: zing_foru
3 Replies

5. UNIX for Dummies Questions & Answers

Gnuplot wxt terminal vs x11 terminal

Hi, I installed ubuntu recently on my pc. And I installed gnuplot as well. When I first started working with gnuplot it was working . I did a plot and when I wanted to fit my data something happened and not the default terminal of gnuplot is xwt! I changed it to: set terminal x11, but it... (0 Replies)
Discussion started by: cosmologist
0 Replies

6. UNIX for Advanced & Expert Users

Pseudo-terminal will not be allocated because stdin is not a terminal.

I am trying to automate a SSH login using Keys using the following command ssh -i id_rsa usernamw@ipaddr. I am successful in doing this and i am getting the Warning Screen and I logon successfully. but when I am executing the command tail -1cf put.dat | ssh -i id_rsa username@ipaddr > get.dat ... (1 Reply)
Discussion started by: Shivdatta
1 Replies

7. UNIX for Dummies Questions & Answers

Some CLI questions

I use Ubuntu Linux, and I'd like to become more familiar with the CLI. I have these questions: 1) How to remove a directory that is not empty? The only option in man rmdir is -p and that does not do what I need. rm -R needs sudo for some reason. 2) What is a CLI command to make all the files... (3 Replies)
Discussion started by: dotancohen
3 Replies

8. UNIX for Advanced & Expert Users

connecting to unix through hyper terminal - as a dumb terminal

I just changed from windows NT to XP and I am no longer able to connect to my unix system. I used to use hyper terminal -- which acts as dumb terminal to my main frame unix system. I think one of the options used to be "direct to comX". This option isn't listed now. I use a serial port and the... (2 Replies)
Discussion started by: michelle
2 Replies

9. UNIX for Dummies Questions & Answers

Solaris Sparc5 and connecting with a PC via Hyper terminal

I am trying to connect to a sparc5 with my PC via a null modem cable from serial port to serial port. I do not have a sun monitor so I am trying to use my PC. I am unsuccessful in even making the basic connection to the sparc box. Any ideas on how to work around this? (7 Replies)
Discussion started by: adrian
7 Replies
Login or Register to Ask a Question