maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Script to connect/disconnect from wifi (https://talk.maemo.org/showthread.php?t=26141)

ichneumon 2009-01-11 01:28

Script to connect/disconnect from wifi
 
1 Attachment(s)
Apologies if this isn't the place to put it, but I know I'd looked for this elsewhere, and hadn't found a command to do this. It'll allow you to manage connections from scripts. Only three parameters; -c iapname to connect and -d to disconnect, whereas -i iapname simply returns the id. Any network names containing spaces should be enclosed by quotes. Also, if the tablet is already connected, you need to disconnect first. On my my tablet, I've placed it at /usr/bin/wifitool.

Code:

#!/bin/sh

# shell script to connect/disconnect from APs by name

iapidbyname() {
  gconftool-2 --all-dirs /system/osso/connectivity/IAP | while read LINE
  do
      if [ $1 == "`gconftool-2 -g $LINE/name 2>/dev/null`" ]; then
        echo $LINE | sed 's|/system/osso/connectivity/IAP/\([0-9abcdef-]*\)|\1|'
        break
      fi
  done
}

# connect by name
if [ "$1" == "-c" ] || [ "$1" == "--connect" ]; then
  IAP=`iapidbyname $2`
  if [ $IAP ]; then
      dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:${IAP} uint32:0
      exit 0
  else
      echo "Network name not found"
      exit 1
  fi
fi

# disconnect
if [ "$1" == "-d" ] || [ "$1" == "--disconnect"  ]; then
  dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  exit 0
fi

# return id for name
if [ "$1" == "-i" ] || [ "$1" == "--id" ]; then
  IAP=`iapidbyname $2`
  if [ $IAP ]; then
      echo $IAP
      exit 0
  else
      echo "Network name not found"
      exit 1
  fi
fi

# Output Help
echo "Usage: $0 option [IAP]"
echo "Option    GNU long option  Meaning"
echo " -h, -?  --help          Show this message"
echo " -c <IAP> --connect <IAP>  Connect to Internet Access Point"
echo " -d      --disconnect    Disconnect current connection"
echo " -i <IAP> --id <IAP>      Show osso id for named IAP"

exit 1

Updated in response to comments. Thanks!

allnameswereout 2009-01-11 12:25

Re: Script to connect/disconnect from wifi
 
Hmm, some AP names contain spaces. Then you need quotes; e.g. wifitool -c "Home Sweet Home"

This should be pretty useful for those who decide to use a newer kernel, not being able to use the connection panel.

codeMonkey 2009-01-11 14:38

Re: Script to connect/disconnect from wifi
 
Code:

#!/bin/sh
May also be slightly more appropriate for those who don't have bash installed (provided there isn't anything in there that's bash specific)

cvmiller 2009-01-11 16:26

Re: Script to connect/disconnect from wifi
 
Look interesting. My only comment, would be to add help, with something like this:

#!/bin/sh

if [ -z $1 ]; then
# needs help
echo "Help is available"
exit
fi

echo "No Help"

xsmabbs 2012-03-21 13:08

Re: Script to connect/disconnect from wifi
 
-it connect to only saved ap,,,i want an scripts for connect to no-saved ap
tanks


All times are GMT. The time now is 07:12.

vBulletin® Version 3.8.8