Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 21 Sep 2017, 15:45
All times are UTC - 4
 Forum index » Advanced Topics » Hardware » Networking » Wireless
Script request - set up wi-fi from command line
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
B.K. Johnson

Joined: 12 Oct 2009
Posts: 626

PostPosted: Sun 13 Mar 2016, 02:59    Post subject:  Script request - set up wi-fi from command line  

Hello
I need to do something but I do not have the programming skills for it.
I would not even attempt to hack /usr/sbin/connectwizard. Laughing I seek the assistance of the network gurus in the community.

After clicking on the InternetConnect desktop icon and selecting Network Wizard, there are a number of screens before connection to the internet is made. I would like to bypass these screens altogether with a script that would invoke the commands.

The pseudocode would look something like this, PERHAPS (remember my comment on my coding skills Embarassed ):


Code:

ifconfig wlan1 up #enable wlan1
TargetEssid="Basil's Place"
iwlist wlan1 scan | egrep ESSID > Interfaceslist #save list of ESSIDs to textfile, Interfaceslist
ListLines =???#get the number of lines in Interfaceslist
for (( scan = 0; scan < ListLines; scan++)

do
  read next line from Interfaceslist to $this
   if substring $this = TargetEssid then
        iwconfig wlan1 enc WFA/TKIP  #    enable WPA/TKIP encryption
        iwconfig wlan1 key mypasskey  #Send the passphrase
        dhcpcd wlan1  #set up dhcp
   fi
endo

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
fabrice_035

Joined: 28 Apr 2014
Posts: 374

PostPosted: Sun 13 Mar 2016, 05:07    Post subject:  

Hello, i have a problem with my puppy, sns broken and connection wizard not better, result i have added this lines in a script placed in startup dir

First, need create a config_file

Code:

wpa_passphrase AccesPointName YOUR_PERSONAL_KEY > /root/config_file

next

and the script in startup dir contain

Code:

wpa_supplicant -iwlan0 -c /root/config_file -Dwext&


option, fix ip

Code:

sleep 1
ifconfig wlan0 192.168.1.200 broadcast 192.168.1.255 netmask 255.255.255.0
route add default gw 192.168.1.1 wlan0


possible help u with that ?
Back to top
View user's profile Send private message 
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: Sun 13 Mar 2016, 16:48    Post subject:  

This may be helpful: http://puppylinux.org/wikka/HowToWifiFromCommand

It is from this thread: http://www.murga-linux.com/puppy/viewtopic.php?t=22469
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 650

PostPosted: Sun 13 Mar 2016, 17:13    Post subject:  

Here's the script I use:
(where "MiFi.WPA2.conf" is the config file I generated with dougal's Network Wizard)

Code:

#!/bin/sh
# - first check your wifi router to see if it uses WPA or WPA2 encryption.
# If WPA, use Geany to open /etc/network-wizard/wireless/wpa_profiles/wpa_supplicant.conf
# If WPA2, use Geany to open /etc/network-wizard/wireless/wpa_profiles/wpa_supplicant2.conf
rfkill unblock wlan
WIFI=$(iwconfig  | grep IEEE|awk {'print $1'})
ifconfig $WIFI down
pkill wpa_supplicant
pkill dhcpcd
ifconfig $WIFI up
rm /var/run/wpa_supplicant/*
wpa_supplicant -i $WIFI -D wext -c /etc/network-wizard/wireless/wpa_profiles/MiFi.WPA2.conf -B
sleep 5
rm -f /var/lib/dhcpcd/*.info
rm -f /var/run/*.pid
dhcpcd -t 30 -h $HOSTNAME -d $WIFI

Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 626

PostPosted: Mon 14 Mar 2016, 00:49    Post subject:  

@jafadmin
Thanks for the script. I can't say I understand it but I have checked out the files referenced. Despite my limited knowledge, I am having doubts whether there is a clear understanding of what I am trying to accomplish. I say this because:

1.I inferred in my pseudocode that I only want to connect to a single access point named "Basil's Place", yet I do not see any named Acces point.
2. Secondly, I may not have been clear, but I do not want to change what is currently offered in a puppy. I want the script to be something additional or to be run elsewhere.
3. I don't see where you scan for available access points.
4. Perhaps I am wrong, but it seems to me from the script that you are assuming that there is a single wireless port - wlan0. This is not so. There are 2 but as shown in the pseudocode, I want to activate only wlan1. Please assume that wlan1 is known to be active, I want to connect to a specific Access Point with a specific ESSID/BSID we will call "Basil's Place". I also know the encryption type and key. If "Basil's Place" is not available, then exit. If available, then enable WPA2, submit key and enable dchp.

As inferred in the pseudocode, I know that the encryption is WPA/TKIP. And the check of /etc/network-wizard/wireless/wpa_profiles/wpa_supplicant.conf confirms it.

Although the script, as written, is unlikely to do what I wish, I'd appreciate if you could go through the script with me. Comments in blue are my interpretation of what the code line does. Correct my misunderstandings, pease.

rfkill unblock wlan$ kill all wlan connections
WIFI=$(iwconfig | grep IEEE|awk {'print $1'}) #prints active interfaces-wlan0, wlan1
#I do not want anything printed
# Isn't this line processed only once?
# What would $WIFI hold after processing? Seems to me it would be wlan0
ifconfig $WIFI down #If $WIFI = wlan0, deactivate it
pkill wpa_supplicant # kill supplicant
pkill dhcpcd # kill dhcp too
ifconfig $WIFI up # activate wlan0
rm /var/run/wpa_supplicant/* # remove an old supplicant if it exists
wpa_supplicant -i $WIFI -D wext -c /etc/network-wizard/wireless/wpa_profiles/MiFi.WPA2.conf -B
# writes configuration file, MiFi.WPA2.conf, using wext not nl80211. Background the process.
sleep 5 # wait a bit
rm -f /var/lib/dhcpcd/*.info #where did this *.info file come fom? I have no .info file. what I have is the
#dhcpcd-wlan1.lease, which makes sense with the dhcpcd command line that follows.
rm -f /var/run/*.pid # this would remove existing .pid
dhcpcd -t 30 -h $HOSTNAME -d $WIFI # and get a new lease (an IP address)

[EDIT]
After reading the links from Wognath, I understand your code better. The major problem, I think, is that you assume a single port. Your code would need a loop in which we search for the target ESSID. However, since there is a known active port (wlan1).and a known ESSID ("Basil's Place"), there is no need for that as shown by raffy here.
iwconfig wlan1 essid "Basil's Place"

Then I found the best template of what I had in mind here But who knows what surprises may turn up as I read more of the thread.

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 626

PostPosted: Mon 14 Mar 2016, 00:55    Post subject:  

@fabrice_035

Thanks for responding. Will check to see what I can use.

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
april


Joined: 14 Sep 2013
Posts: 974
Location: Water winging it back home to Cairns finally

PostPosted: Mon 14 Mar 2016, 17:23    Post subject:  

I think jafadmin was just trying to help you get started not do the job for you.
Back to top
View user's profile Send private message Yahoo Messenger 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 626

PostPosted: Mon 14 Mar 2016, 20:41    Post subject:  

@april
If the post came across as being critical of jafadmin's effort, rest assured it was not intended.
I thanked him. I acknowledged that I did not understand all the code and invited him to explain, the lines and correct my understanding of them if needed.

But I did state in my post that I was not a coder and I was asking for a script (not a code fragment or otherwise) that would accomplish a task. So, a script addressing my problem was uppermost in my mind but read on ...

@jafadmin
My apologies if you feel slighted by my response. As I stated to april, I did not intend to be critical. But on rereading your post, I was definitely at fault for you stated from the outset: Here's the script I use : In my anxiety to see the code presented, I missed that statement. In the circumstances, none of the 3 numbered points at the beginning of my response to you are apropos and for that error, I apologize.

The invitation to help me understand the code lines still stands.

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 650

PostPosted: Mon 14 Mar 2016, 22:28    Post subject:  

The file: "/etc/network-wizard/wireless/wpa_profiles/MiFi.WPA2.conf" contains the ESSID & passphrase

Run the network wizard to try to connect. It will create a "WPA2.conf" file with some name unique to your nic mac address in the path specified above. I rename mine for convenience.

Drop a copy of the script edited with the path to YOUR "WPA2.conf" file into your "Startup" folder, and you will connect to that WAP every time you boot. No muss, no fuss.

I encourage you to inspect the format of the "WPA2.conf" file to increase your understanding.
Back to top
View user's profile Send private message 
B.K. Johnson

Joined: 12 Oct 2009
Posts: 626

PostPosted: Tue 15 Mar 2016, 01:39    Post subject:  

@jafadmin
Confirmations:
    I am using WPA
    My equivalent of your MiFi.WPA2.conf has the ssid and passphrase etc.
I have edited your script for equivalent WPA2.conf but not as yet placed it in Startup

One issue bothers me: Confused
If there is a single wireless port, wlan0, then after this line is processed'
Code:
WIFI=$(iwconfig  | grep IEEE|awk {'print $1'})

WIFI=wlan0 Cool
I very much doubt that the value will be the same if there are 2 wireless ports (which I have) and I want to use wlan1?

To overcome that, I am considering replacing that line with:
Code:
$WIFI=wlan1 # always use wlan1

Do you have a better idea?

_________________
B.K. Johnson
tahrpup-6.0.5 PAE (upgraded from 6.0 =>6.0.2=>6.0.3=>6.0.5 via quickpet/PPM=Not installed); slacko-5.7 occasionally. Frugal install, pupsave file, multi OS flashdrive, FAT32 , SYSLINUX boot, CPU-Dual E2140, 4GB RAM

Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 650

PostPosted: Tue 15 Mar 2016, 02:25    Post subject:  

You are correct. The script will grab the first available wireless device. I wrote it that way for use on my thumbdrive versions of puppy. I can boot any laptop and automatically get a wireless network connection.

[edit] In that script, I first shut down the wlan and kill all associated processes, then bring it back up. Why? Because then, simply clicking an icon to the script will reset my wireless , if necessary, without any messy tweaking.

In your case, I would definitely manually assign the wifi nic device to use.

I hope this has helped your understanding of scripting, and WPA wireless. From now on you will be able to help those with a similar problem.

Cheers Cool
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Hardware » Networking » Wireless
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3092s ][ Queries: 11 (0.0186s) ][ GZIP on ]