WiFi script.

Well I made a wifi script for myself because netcfg didn't like working and I was tired of my makeshift connect script. So I made this ruby script to help me learn and to have a useful connect script so I thought that others might find it useful.
#!/usr/bin/ruby
# kukri
$help = <<HELP
Kukri
WiFi script by Dart27 <[email protected]>
usage
scriptname [interface]
-s --scan Scans for access points.
-c --connect SSID {Hexkey|s:asciikey} Connect to an access point
-d --disconnect Disconnect from current access point
-h --help Displays this help and exits
-i --information Displays SSID and signal strength
You can edit the source file to change the default interface and DHCP client.
Note for wep users, if you are using an ascii key, prepend a "s:" to your key.
ex: kukri -c accesspoint s:password
Missing a feature? Contact me.
HELP
INTERFACE = :wlan0 # Edit for default extension
DHCPCLIENT = :dhclient # Edit for default dhcp client
class WifiTools
def initialize interface = INTERFACE
@interface = interface
end
def scan
networks = `iwlist #{@interface} scan`.split(/Cell \d*/)
networks.shift
networks.each do |results|
puts results.match(/SSID:\".*"/).to_s.gsub('"','')
print "\t", results.match(/Channel:\d+/).to_s.concat("\n")
print "\t", results.match(/Quality=\d+\/\d+/).to_s.sub("Quality=",'Strenth:').to_s.concat("\n")
print "\t", results.match(/Encryption .*\s/).to_s.sub(' ',':')
end
end
def connect essid, key = nil
if `sudo ifconfig wlan0 up` != ''
abort("Please run the script using sudo or as root")
end
unless key
puts "Connecting to #{essid}"
if `sudo iwconfig #{@interface} essid #{essid}` == ''
puts "Connected to #{essid}"
else
abort("Could not connect")
end
else
puts "Connecting to #{essid} with WEP encryption"
if `sudo iwconfig #{@interface} essid #{essid} key #{key}` == ''
puts "Connected to #{essid}"
else
abort("Could not connect")
end
end
`sudo #{DHCPCLIENT} -q -n #{@interface}`
puts "#{DHCPCLIENT.to_s.capitalize} started."
end
def disconnect
"Disconnecting #{@interface}"
if `sudo iwconfig #{@interface} essid off` != ''
"Disconnect failed! Try running as root"
end
end
def information
"Current Connection"
info = `iwconfig #{@interface}`
puts info.match(/SSID:\".*"/)
puts info.match(/Quality=\d+\/\d+/).to_s.sub("Quality=",'Strenth:')
end
end
#wifi = Config.new(ARGV.first) if ARGV.first =~ /\w\d/ else
case ARGV.first()
when /\w\w/
wifi = WifiTools.new(ARGV.shift)
else
wifi = WifiTools.new()
end
case ARGV.first()
when "--scan", "-s"
wifi.scan
when "--connect", "-c"
wifi.connect ARGV[1], ARGV[2]
when "--disconect", "-d"
wifi.disconnect
when "--information", "-i"
wifi.information
when "--help", "-h"
print $help
else
print $help
end

Because this isn't a project and netcfg didn't work for me. So I just made something that will work without a lot of hassle.

Similar Messages

  • Dead-simple bashscript wifi connector

    I've been a wicd user for quite some time and it has generally worked very well for me.  However, it does seem to do an aweful lot, and I wasn't sure I needed all that.  This abundance of features also made it a little slower than I liked.  Recently, too, when wicd first starts, it "rescans" for networks several times before it allows me to finally connect to any of the discovered networks.  I have seen other users mention this last concern too.[1]
    Other recent wifi issues caused me to have to get used to the 'manual' methods of connecting.  I really started preferring the manual methods, except for the fact that there was a lot of repetition of the same steps every time I wanted to connect.  This seemed like a perfect job for a simple script.  And so I created my new wifi script.
    To use just type `wifi`.  You'll be given a list of available networks.  Enter the number for your choice.  If it is an unsecured network, then you are done.  If you choose a secure network (highlighted in red in the list) and if that network hasn't been set up via "wpa_passphrase" then wifi will inform you of the error and tell you how to fix it: run "wifi new <ssid> <passphrase>".  This will configure wpa_supplicant for that network* then it will give you the list with the option to connect to that secure network.
    *Note: This only does the most basic wpa_supplicant.conf set up from wpa_passphrase.  If more is needed that will (currently) have to be done manually, but only once per network.  I may improve this, or perhaps not, as I don't mind manually configuring the file once for each new network.
    "Wifi" was written for a 256 color terminal.  If you don't have a 256 color terminal, then change/delete the escape color codes.
    UPDATE: Get it at the link in my signature.
    [1]: An example of this problem with a potential solution for anyone who wants to stick with wicd.  I checked my wicd config, and it apparently stored info on every network I had ever connected to - it was a HUGE file.
    Last edited by Trilby (2012-06-25 17:52:03)

    Trilby wrote:I just added a image of what it should look like with the default colors:
    https://github.com/TrilbyWhite/Wifi/blo … r/wifi.png
    Yes, when I run the script in console under X11 (e.g. urxvt), everything looks correct.
    The only problem is when I run in TTY without X.
    Trilby wrote:I could make a more tty-friendly version.
    I was thinking of simpler hack, about detecting if the required features are supported.
    If not, the script could simply print error message and give up.
    Perhaps check based on this could do the job:
    $ tput colors
    In my TTYs, it gives 8, what explains the mess

  • [SOLVED] awesomewm vicious.widgets.wifi returns nil

    I cant seem to figure out why the returning args (all of them) are nil..
    this is the widget code I have:
    wifiwidget = wibox.widget.textbox()
    vicious.register(wifiwidget, vicious.widgets.wifi,
    function( widget, args)
    return string.format("%.8s - %sdB", args[1], args[7])
    end, 19, "wlp2s0")
    although, i feel thats not the culprit because regardless of what i put there, every entry in args[] is nil.
    I have iwconfig installed and it returns the correct information for wlp2s0
    vicious wifi script is in /usr/share/lua/5.2/vicious/widgets
    any thoughts or further info needed?
    Last edited by pdizzle (2014-10-02 13:18:42)

    resolved...
    in the case of the wifi widget, the returned value is a table.
    so to call the values i was looking for it should be formatted:
    wifiwidget = wibox.widget.textbox()
    vicious.register(wifiwidget, vicious.widgets.wifi,
    function( widget, args)
    return string.format("%.8s - %sdB", args["{ssid}"], args["{sign}"])
    end, 19, "wlp2s0")

  • Bash script to connect to strongest unencrypted wifi AP

    Here's a little bash script that looks at the available wifi APs that your card can see, and automatically connects you to the AP with the highest quality and that is also unencrypted. I'm just posting it in case anyone wants to improve upon it or use it. And yes, my bash knowledge kinda sucks.
    Just call it like "wifi.sh wlan0" as root.
    #!/bin/bash
    # Finds the strongest unencrypted AP and tries to connect to it via dhcp
    # Call this script like "wifi.sh wlan0"
    interface=$1
    iwlist $interface scan > blah
    NumAPs=`cat blah | grep ESSID | wc -l`
    BestAP=0
    BestQuality=-1
    for i in `seq 1 $NumAPs`;
    do
    # Check if AP is encrypted
    Encryption=`cat blah | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
    if [ $Encryption = "off" ]; then
    # Find AP with the highest quality
    QUALITY=`cat blah | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    if [ $QUALITY -gt $BestQuality ]; then
    BestQuality=$QUALITY
    BestAP=$i
    fi
    fi
    done
    if [ $BestAP -gt 0 ]; then
    # Yay, we found an unencrypted AP:
    echo Connecting to...
    ESSID=`cat blah | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
    echo ESSID=$ESSID
    MODE=`cat blah | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
    echo Mode=$MODE
    CHANNEL=`cat blah | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
    echo Channel=$CHANNEL
    # Connect
    iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
    if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
    rm /etc/dhcpc/dhcpcd-${interface}.pid
    fi
    dhcpcd $interface
    # Cleanup
    rm blah
    fi

    For whatever reason, your quality line uses an equal sign whereas every other line of your scan has a colon (and most people have a colon for every line). Too weird..
    Anyway, give this a shot:
    #!/bin/bash
    # Finds the strongest unencrypted AP and tries to connect to it via dhcp
    # Call this script like "wifi.sh wlan0"
    TEMP=/tmp/bestap.tmp
    LOCK=/var/lock/bestap.lock
    if [ `whoami` != "root" ];then
    echo "Sorry, you need to be root to run this program"
    exit 1
    fi
    if [[ -z $1 ]];then
    echo "USAGE: $0 device"
    exit 1
    else
    interface=$1
    fi
    # Checking for lock
    if [[ -e $LOCK ]];then
    exit 1; # Too simply nothing to do here :)
    else
    touch $TEMP $LOCK
    fi
    isNotInteger()
    x=$1
    case $x in
    *[!0-9])
    return 0 ;;
    return 1 ;;
    esac
    # Proggy
    iwlist $interface scan > $TEMP
    NumAPs=`cat $TEMP | grep ESSID | wc -l`
    BestAP=0
    BestQuality=-1
    for i in `seq 1 $NumAPs`;
    do
    # Check if AP is encrypted
    Encryption=`cat $TEMP | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
    if [ $Encryption = "off" ]; then
    # Find AP with the highest quality
    QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    if isNotInteger "$QUALITY"; then
    # If we didn't find an integer, try this instead:
    QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d"=" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    fi
    if [ "$QUALITY" -gt "$BestQuality" ]; then
    BestQuality=$QUALITY
    BestAP=$i
    fi
    fi
    done
    if [ $BestAP -gt 0 ]; then
    # Yay, we found an unencrypted AP:
    echo Connecting to...
    ESSID=`cat $TEMP | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
    echo ESSID=$ESSID
    MODE=`cat $TEMP | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
    echo Mode=$MODE
    CHANNEL=`cat $TEMP | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
    echo Channel=$CHANNEL
    # Connect
    iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
    if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
    rm /etc/dhcpc/dhcpcd-${interface}.pid
    fi
    dhcpcd $interface
    # Cleanup
    fi
    rm -f $TEMP $LOCK

  • Scripting changes of WiFi Networks

    Hi,
    I've got different network settings for each WiFi Network I connect to. I got fed up changing the location each time I moved. So I used a script called SleepWatcher to run a script to select the correct Location for the current WiFi when waking from Sleep.
    I then had to put a separate script to open the correct location on boot.
    It occurs to me there must be a better way of doing this. I seem to remember seeing a script that is supposed to be run each time the WiFi network changes, but I couldn't find it on my machine. What is the official line on this? What scripts are run when the WiFi Network is changed?
    A1025   Mac OS X (10.4.8)   Pwerbook G4

    I changed my router from channel 11 to auto and it's now working fine.
    There was no sign of any interference on 11 and indeed all the other wifi devices could use it without problems & the macbook itself would eventually connect.
    But now that it's auto it connects almost instantly.

  • HTTP Proxy / Auto config script on Wifi

    I am currently running a Curve 9220. I am in an area where the WiFi network requires an http proxy and port to be inputted along with authentication or the automatic configuration script can also be entered along with pop-up window for authentication. How can i enter these settings into my BB to make my wifi work?

    Hey daraius1995,
    Welcome to the BlackBerry® Support Community Forums.
    The BlackBerry smartphone does not have an option to configure HTTP Proxy for Wi-Fi, this is by design. For more information please see the following article:
    No option to configure HTTP Proxy for Wi-Fi on the BlackBerry smartphone
    http://btsc.webapps.blackberry.com/btsc/KB32112
    Thanks.
    -HB
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • [script] create_ap: Create a NATed or Bridged WiFi Access Point

    This script use hostapd + dnsmasq + iptables to create a NATed Access Point OR hostapd + brctl + dhclient to create a bridged Access Point.
    The default behavior is a NATed Access Point.
    updated script will be here: https://github.com/oblique/create_ap and http://git.2f30.org/create_ap/
    Examples
    No passphrase (open network):
    ./create_ap wlan0 eth0 MyAccessPoint
    OR
    echo -e "MyAccessPoint" | ./create_ap wlan0 eth0
    WPA + WPA2 passphrase:
    ./create_ap wlan0 eth0 MyAccessPoint MyPassPhrase
    OR
    echo -e "MyAccessPoint\nMyPassPhrase" | ./create_ap wlan0 eth0
    AP without Internet sharing:
    ./create_ap -n wlan0 MyAccessPoint MyPassPhrase
    Bridged Internet sharing:
    ./create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase
    Internet sharing from the same WiFi interface:
    ./create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase
    Usage
    Usage: create_ap [options] <wifi-interface> [<interface-with-internet>] [<access-point-name> [<passphrase>]]
    Options:
    -h, --help Show this help
    -c <channel> Channel number (default: 1)
    -w <WPA version> Use 1 for WPA, use 2 for WPA2, use 1+2 for both (default: 1+2)
    -n Disable Internet sharing (if you use this, don't pass
    the <interface-with-internet> argument)
    -m <method> Method for Internet sharing.
    Use: 'nat' for NAT (default)
    'bridge' for bridging
    'none' for no Internet sharing (equivalent to -n)
    --hidden Make the Access Point hidden (do not broadcast the SSID)
    --ieee80211n Enable IEEE 802.11n (HT)
    --ht_capab <HT> HT capabilities (default: [HT40+])
    --driver Choose your WiFi adapter driver (default: nl80211)
    --no-virt Do not create virtual interface
    Non-Bridging Options:
    -g <gateway> IPv4 Gateway for the Access Point (default: 192.168.12.1)
    -d DNS server will take into account /etc/hosts
    Useful informations:
    * If you're not using the --no-virt option, then you can create an AP with the same
    interface you are getting your Internet connection.
    * You can pass your SSID and password through pipe or through arguments (see examples).
    Examples:
    create_ap wlan0 eth0 MyAccessPoint MyPassPhrase
    echo -e 'MyAccessPoint\nMyPassPhrase' | create_ap wlan0 eth0
    create_ap wlan0 eth0 MyAccessPoint
    echo 'MyAccessPoint' | create_ap wlan0 eth0
    create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase
    create_ap -n wlan0 MyAccessPoint MyPassPhrase
    create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase
    create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase
    Code
    #!/bin/bash
    # general dependencies:
    # bash (to run this script)
    # util-linux (for getopt)
    # hostapd
    # iproute2
    # iw
    # iwconfig (you only need this if 'iw' can not recognize your adapter)
    # haveged (optional)
    # dependencies for 'nat' or 'none' Internet sharing method
    # dnsmasq
    # iptables
    # dependencies for 'bridge' Internet sharing method
    # bridge-utils
    usage() {
    echo "Usage: $(basename $0) [options] <wifi-interface> [<interface-with-internet>] [<access-point-name> [<passphrase>]]"
    echo
    echo "Options:"
    echo " -h, --help Show this help"
    echo " -c <channel> Channel number (default: 1)"
    echo " -w <WPA version> Use 1 for WPA, use 2 for WPA2, use 1+2 for both (default: 1+2)"
    echo " -n Disable Internet sharing (if you use this, don't pass"
    echo " the <interface-with-internet> argument)"
    echo " -m <method> Method for Internet sharing."
    echo " Use: 'nat' for NAT (default)"
    echo " 'bridge' for bridging"
    echo " 'none' for no Internet sharing (equivalent to -n)"
    echo " --hidden Make the Access Point hidden (do not broadcast the SSID)"
    echo " --ieee80211n Enable IEEE 802.11n (HT)"
    echo " --ht_capab <HT> HT capabilities (default: [HT40+])"
    echo " --driver Choose your WiFi adapter driver (default: nl80211)"
    echo " --no-virt Do not create virtual interface"
    echo
    echo "Non-Bridging Options:"
    echo " -g <gateway> IPv4 Gateway for the Access Point (default: 192.168.12.1)"
    echo " -d DNS server will take into account /etc/hosts"
    echo
    echo "Useful informations:"
    echo " * If you're not using the --no-virt option, then you can create an AP with the same"
    echo " interface you are getting your Internet connection."
    echo " * You can pass your SSID and password through pipe or through arguments (see examples)."
    echo
    echo "Examples:"
    echo " $(basename $0) wlan0 eth0 MyAccessPoint MyPassPhrase"
    echo " echo -e 'MyAccessPoint\nMyPassPhrase' | $(basename $0) wlan0 eth0"
    echo " $(basename $0) wlan0 eth0 MyAccessPoint"
    echo " echo 'MyAccessPoint' | $(basename $0) wlan0 eth0"
    echo " $(basename $0) wlan0 wlan0 MyAccessPoint MyPassPhrase"
    echo " $(basename $0) -n wlan0 MyAccessPoint MyPassPhrase"
    echo " $(basename $0) -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase"
    echo " $(basename $0) --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase"
    # it takes 2 arguments
    # returns:
    # 0 if v1 (1st argument) and v2 (2nd argument) are the same
    # 1 if v1 is less than v2
    # 2 if v1 is greater than v2
    version_cmp() {
    [[ ! $1 =~ ^[0-9]+(\.[0-9]+)*$ ]] && die "Wrong version format!"
    [[ ! $2 =~ ^[0-9]+(\.[0-9]+)*$ ]] && die "Wrong version format!"
    V1=( $(echo $1 | tr '.' ' ') )
    V2=( $(echo $2 | tr '.' ' ') )
    VN=${#V1[@]}
    [[ $VN -lt ${#V2[@]} ]] && VN=${#V2[@]}
    for ((x = 0; x < $VN; x++)); do
    [[ ${V1[x]} -lt ${V2[x]} ]] && return 1
    [[ ${V1[x]} -gt ${V2[x]} ]] && return 2
    done
    return 0
    USE_IWCONFIG=0
    is_wifi_interface() {
    which iw > /dev/null 2>&1 && iw dev $1 info > /dev/null 2>&1 && return 0
    if which iwconfig > /dev/null 2>&1 && iwconfig $1 > /dev/null 2>&1; then
    USE_IWCONFIG=1
    return 0
    fi
    return 1
    get_phy_device() {
    for x in /sys/class/ieee80211/*; do
    [[ ! -d "$x" ]] && continue
    if [[ "${x##*/}" = "$1" ]]; then
    echo $1
    return 0
    elif [[ -e "$x/device/net/$1" ]]; then
    echo ${x##*/}
    return 0
    elif [[ -e "$x/device/net:$1" ]]; then
    echo ${x##*/}
    return 0
    fi
    done
    echo "Failed to get phy interface" >&2
    return 1
    get_adapter_info() {
    PHY=$(get_phy_device "$1")
    [[ $? -ne 0 ]] && return 1
    iw phy $PHY info
    can_have_sta_and_ap() {
    # iwconfig does not provide this information, assume false
    [[ $USE_IWCONFIG -eq 1 ]] && return 1
    get_adapter_info "$1" | grep -E '{.* managed.* AP.*}' > /dev/null 2>&1 && return 0
    get_adapter_info "$1" | grep -E '{.* AP.* managed.*}' > /dev/null 2>&1 && return 0
    return 1
    can_have_ap() {
    # iwconfig does not provide this information, assume true
    [[ $USE_IWCONFIG -eq 1 ]] && return 0
    get_adapter_info "$1" | grep -E '\* AP$' > /dev/null 2>&1 && return 0
    return 1
    can_transmit_to_channel() {
    IFACE=$1
    CHANNEL=$2
    if [[ $USE_IWCONFIG -eq 0 ]]; then
    CHANNEL_INFO=$(get_adapter_info ${IFACE} | grep "MHz \[${CHANNEL}\]")
    [[ -z "${CHANNEL_INFO}" ]] && return 1
    [[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1
    [[ "${CHANNEL_INFO}" == *disabled* ]] && return 1
    return 0
    else
    CHANNEL=$(printf '%02d' ${CHANNEL})
    CHANNEL_INFO=$(iwlist ${IFACE} channel | grep "Channel ${CHANNEL} :")
    [[ -z "${CHANNEL_INFO}" ]] && return 1
    return 0
    fi
    is_wifi_connected() {
    if [[ $USE_IWCONFIG -eq 0 ]]; then
    iw dev "$1" link 2>&1 | grep -E '^Connected to' > /dev/null 2>&1 && return 0
    else
    iwconfig "$1" 2>&1 | grep -E 'Access Point: [0-9a-fA-F]{2}:' > /dev/null 2>&1 && return 0
    fi
    return 1
    get_macaddr() {
    ip link show "$1" | grep ether | grep -Eo '([0-9a-f]{2}:){5}[0-9a-f]{2}[[:space:]]' | tr -d '[[:space:]]'
    get_avail_bridge() {
    for i in {0..100}; do
    curr_bridge=$(brctl show | grep "br$i" | cut -s -f1)
    if [[ -z $curr_bridge ]]; then
    echo "br$i"
    return
    fi
    done
    get_new_macaddr() {
    OLDMAC=$(get_macaddr "$1")
    for i in {20..255}; do
    NEWMAC="${OLDMAC%:*}:$(printf %02x $i)"
    (ip link | grep "ether ${NEWMAC}" > /dev/null 2>&1) || break
    done
    echo $NEWMAC
    ADDED_UNMANAGED=0
    NETWORKMANAGER_CONF=/etc/NetworkManager/NetworkManager.conf
    NM_OLDER_VERSION=1
    networkmanager_exists() {
    which nmcli > /dev/null 2>&1 || return 1
    NM_VER=$(nmcli -v | grep -m1 -oE '[0-9]+(\.[0-9]+)*\.[0-9]+')
    version_cmp $NM_VER 0.9.10
    if [[ $? -eq 1 ]]; then
    NM_OLDER_VERSION=1
    else
    NM_OLDER_VERSION=0
    fi
    return 0
    networkmanager_is_running() {
    networkmanager_exists || return 1
    if [[ $NM_OLDER_VERSION -eq 1 ]]; then
    NMCLI_OUT=$(nmcli -t -f RUNNING nm)
    else
    NMCLI_OUT=$(nmcli -t -f RUNNING g)
    fi
    [[ "$NMCLI_OUT" == "running" ]]
    networkmanager_iface_is_unmanaged() {
    nmcli -t -f DEVICE,STATE d | grep -E "^$1:unmanaged$" > /dev/null 2>&1
    ADDED_UNMANAGED=
    networkmanager_add_unmanaged() {
    networkmanager_exists || return 1
    [[ -d ${NETWORKMANAGER_CONF%/*} ]] || mkdir -p ${NETWORKMANAGER_CONF%/*}
    [[ -f ${NETWORKMANAGER_CONF} ]] || touch ${NETWORKMANAGER_CONF}
    if [[ $NM_OLDER_VERSION -eq 1 ]]; then
    if [[ -z "$2" ]]; then
    MAC=$(get_macaddr "$1")
    else
    MAC="$2"
    fi
    [[ -z "$MAC" ]] && return 1
    fi
    UNMANAGED=$(grep -m1 -Eo '^unmanaged-devices=[[:alnum:]:;,-]*' /etc/NetworkManager/NetworkManager.conf | sed 's/unmanaged-devices=//' | tr ';,' ' ')
    WAS_EMPTY=0
    [[ -z "$UNMANAGED" ]] && WAS_EMPTY=1
    for x in $UNMANAGED; do
    [[ $x == "mac:${MAC}" ]] && return 2
    [[ $NM_OLDER_VERSION -eq 0 && $x == "interface-name:${1}" ]] && return 2
    done
    if [[ $NM_OLDER_VERSION -eq 1 ]]; then
    UNMANAGED="${UNMANAGED} mac:${MAC}"
    else
    UNMANAGED="${UNMANAGED} interface-name:${1}"
    fi
    UNMANAGED=$(echo $UNMANAGED | sed -e 's/^ //')
    UNMANAGED="${UNMANAGED// /;}"
    UNMANAGED="unmanaged-devices=${UNMANAGED}"
    if ! grep -E '^\[keyfile\]' ${NETWORKMANAGER_CONF} > /dev/null 2>&1; then
    echo -e "\n\n[keyfile]\n${UNMANAGED}" >> ${NETWORKMANAGER_CONF}
    elif [[ $WAS_EMPTY -eq 1 ]]; then
    sed -e "s/^\(\[keyfile\].*\)$/\1\n${UNMANAGED}/" -i ${NETWORKMANAGER_CONF}
    else
    sed -e "s/^unmanaged-devices=.*/${UNMANAGED}/" -i ${NETWORKMANAGER_CONF}
    fi
    ADDED_UNMANAGED="${ADDED_UNMANAGED} ${1} "
    return 0
    networkmanager_rm_unmanaged() {
    networkmanager_exists || return 1
    [[ ! -f ${NETWORKMANAGER_CONF} ]] && return 1
    if [[ $NM_OLDER_VERSION -eq 1 ]]; then
    if [[ -z "$2" ]]; then
    MAC=$(get_macaddr "$1")
    else
    MAC="$2"
    fi
    [[ -z "$MAC" ]] && return 1
    fi
    UNMANAGED=$(grep -m1 -Eo '^unmanaged-devices=[[:alnum:]:;,-]*' /etc/NetworkManager/NetworkManager.conf | sed 's/unmanaged-devices=//' | tr ';,' ' ')
    [[ -z "$UNMANAGED" ]] && return 1
    [[ -n "$MAC" ]] && UNMANAGED=$(echo $UNMANAGED | sed -e "s/mac:${MAC}\( \|$\)//g")
    UNMANAGED=$(echo $UNMANAGED | sed -e "s/interface-name:${1}\( \|$\)//g")
    UNMANAGED=$(echo $UNMANAGED | sed -e 's/ $//')
    if [[ -z "$UNMANAGED" ]]; then
    sed -e "/^unmanaged-devices=.*/d" -i ${NETWORKMANAGER_CONF}
    else
    UNMANAGED="${UNMANAGED// /;}"
    UNMANAGED="unmanaged-devices=${UNMANAGED}"
    sed -e "s/^unmanaged-devices=.*/${UNMANAGED}/" -i ${NETWORKMANAGER_CONF}
    fi
    ADDED_UNMANAGED="${ADDED_UNMANAGED/ ${1} /}"
    return 0
    networkmanager_rm_unmanaged_if_needed() {
    [[ $ADDED_UNMANAGED =~ .*\ ${1}\ .* ]] && networkmanager_rm_unmanaged ${1}
    networkmanager_wait_until_unmanaged() {
    networkmanager_is_running || return 1
    while ! networkmanager_iface_is_unmanaged "$1"; do
    sleep 1
    done
    sleep 2
    return 0
    CHANNEL=1
    GATEWAY=192.168.12.1
    WPA_VERSION=1+2
    ETC_HOSTS=0
    HIDDEN=0
    SHARE_METHOD=nat
    IEEE80211N=0
    HT_CAPAB='[HT40+]'
    DRIVER=nl80211
    NO_VIRT=0
    CONFDIR=
    WIFI_IFACE=
    VWIFI_IFACE=
    INTERNET_IFACE=
    BRIDGE_IFACE=
    OLD_IP_FORWARD=
    OLD_BRIDGE_IPTABLES=
    OLD_MACADDR=
    cleanup() {
    trap "" SIGINT
    echo
    echo "Doing cleanup..."
    # exiting
    for x in $CONFDIR/*.pid; do
    # even if the $CONFDIR is empty, the for loop will assign
    # a value in $x. so we need to check if the value is a file
    [[ -f $x ]] && kill -9 $(cat $x)
    done
    rm -rf $CONFDIR
    if [[ "$SHARE_METHOD" != "none" ]]; then
    if [[ "$SHARE_METHOD" == "nat" ]]; then
    iptables -t nat -D POSTROUTING -o ${INTERNET_IFACE} -j MASQUERADE > /dev/null 2>&1
    iptables -D FORWARD -i ${WIFI_IFACE} -s ${GATEWAY%.*}.0/24 -j ACCEPT > /dev/null 2>&1
    iptables -D FORWARD -i ${INTERNET_IFACE} -d ${GATEWAY%.*}.0/24 -j ACCEPT > /dev/null 2>&1
    [[ -n $OLD_IP_FORWARD ]] && echo $OLD_IP_FORWARD > /proc/sys/net/ipv4/ip_forward
    elif [[ "$SHARE_METHOD" == "bridge" ]]; then
    ip link set down $BRIDGE_IFACE
    brctl delbr $BRIDGE_IFACE
    [[ -n $OLD_BRIDGE_IPTABLES ]] && echo $OLD_BRIDGE_IPTABLES > /proc/sys/net/bridge/bridge-nf-call-iptables
    fi
    fi
    if [[ "$SHARE_METHOD" != "bridge" ]]; then
    iptables -D INPUT -p tcp -m tcp --dport 53 -j ACCEPT > /dev/null 2>&1
    iptables -D INPUT -p udp -m udp --dport 53 -j ACCEPT > /dev/null 2>&1
    iptables -D INPUT -p udp -m udp --dport 67 -j ACCEPT > /dev/null 2>&1
    fi
    if [[ $NO_VIRT -eq 0 ]]; then
    if [[ -n $VWIFI_IFACE ]]; then
    ip link set down dev ${VWIFI_IFACE}
    ip addr flush ${VWIFI_IFACE}
    networkmanager_rm_unmanaged_if_needed ${VWIFI_IFACE} ${OLD_MACADDR}
    iw dev ${VWIFI_IFACE} del
    fi
    else
    ip link set down dev ${WIFI_IFACE}
    ip addr flush ${WIFI_IFACE}
    networkmanager_rm_unmanaged_if_needed ${WIFI_IFACE}
    fi
    die() {
    [[ -n "$1" ]] && echo -e "\nERROR: $1\n" >&2
    cleanup
    exit 1
    clean_exit() {
    cleanup
    exit 0
    # if the user press ctrl+c then execute die()
    trap "die" SIGINT
    ARGS=$(getopt -o hc:w:g:dnm: -l "help","hidden","ieee80211n","ht_capab:","driver:","no-virt" -n $(basename $0) -- "$@")
    [[ $? -ne 0 ]] && exit 1
    eval set -- "$ARGS"
    while :; do
    case "$1" in
    -h|--help)
    usage >&2
    exit 1
    --hidden)
    shift
    HIDDEN=1
    -c)
    shift
    CHANNEL="$1"
    shift
    -w)
    shift
    WPA_VERSION="$1"
    shift
    -g)
    shift
    GATEWAY="$1"
    shift
    -d)
    shift
    ETC_HOSTS=1
    -n)
    shift
    SHARE_METHOD=none
    -m)
    shift
    SHARE_METHOD="$1"
    shift
    --ieee80211n)
    shift
    IEEE80211N=1
    --ht_capab)
    shift
    HT_CAPAB="$1"
    shift
    --driver)
    shift
    DRIVER="$1"
    shift
    --no-virt)
    shift
    NO_VIRT=1
    shift
    break
    esac
    done
    if [[ $# -lt 1 ]]; then
    usage >&2
    exit 1
    fi
    if [[ $(id -u) -ne 0 ]]; then
    echo "You must run it as root." >&2
    exit 1
    fi
    WIFI_IFACE=$1
    if ! is_wifi_interface ${WIFI_IFACE}; then
    echo "ERROR: '${WIFI_IFACE}' is not a WiFi interface" >&2
    exit 1
    fi
    if ! can_have_ap ${WIFI_IFACE}; then
    echo "ERROR: Your adapter does not support AP (master) mode" >&2
    exit 1
    fi
    if ! can_have_sta_and_ap ${WIFI_IFACE}; then
    if is_wifi_connected ${WIFI_IFACE}; then
    echo "ERROR: Your adapter can not be connected to an AP and at the same time transmit as an AP" >&2
    exit 1
    elif [[ $NO_VIRT -eq 0 ]]; then
    echo "WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt" >&2
    NO_VIRT=1
    fi
    fi
    if [[ "$SHARE_METHOD" != "nat" && "$SHARE_METHOD" != "bridge" && "$SHARE_METHOD" != "none" ]]; then
    echo "ERROR: Wrong Internet sharing method" >&2
    echo
    usage >&2
    exit 1
    fi
    if [[ "$SHARE_METHOD" == "bridge" ]]; then
    OLD_BRIDGE_IPTABLES=$(cat /proc/sys/net/bridge/bridge-nf-call-iptables)
    BRIDGE_IFACE=$(get_avail_bridge)
    if [[ -z $BRIDGE_IFACE ]]; then
    echo "ERROR: No availabe bridges < br100" >&2
    exit 1
    fi
    elif [[ "$SHARE_METHOD" == "nat" ]]; then
    OLD_IP_FORWARD=$(cat /proc/sys/net/ipv4/ip_forward)
    fi
    if [[ "$SHARE_METHOD" != "none" ]]; then
    MIN_REQUIRED_ARGS=2
    else
    MIN_REQUIRED_ARGS=1
    fi
    if [[ $# -gt $MIN_REQUIRED_ARGS ]]; then
    if [[ "$SHARE_METHOD" != "none" ]]; then
    if [[ $# -ne 3 && $# -ne 4 ]]; then
    usage >&2
    exit 1
    fi
    INTERNET_IFACE=$2
    SSID=$3
    PASSPHRASE=$4
    else
    if [[ $# -ne 2 && $# -ne 3 ]]; then
    usage >&2
    exit 1
    fi
    SSID=$2
    PASSPHRASE=$3
    fi
    else
    if [[ "$SHARE_METHOD" != "none" ]]; then
    if [[ $# -ne 2 ]]; then
    usage >&2
    exit 1
    fi
    INTERNET_IFACE=$2
    fi
    if tty -s; then
    read -p "SSID: " SSID
    while :; do
    read -p "Passphrase: " -s PASSPHRASE
    echo
    read -p "Retype passphrase: " -s PASSPHRASE2
    echo
    if [[ "$PASSPHRASE" != "$PASSPHRASE2" ]]; then
    echo "Passphrases do not match."
    else
    break
    fi
    done
    else
    read SSID
    read PASSPHRASE
    fi
    fi
    if [[ $NO_VIRT -eq 1 && "$WIFI_IFACE" == "$INTERNET_IFACE" ]]; then
    echo -n "ERROR: You can not share your connection from the same" >&2
    echo " interface if you are using --no-virt option." >&2
    exit 1
    fi
    CONFDIR=$(mktemp -d /tmp/create_ap.${WIFI_IFACE}.conf.XXXXXXXX)
    echo "Config dir: $CONFDIR"
    if [[ $NO_VIRT -eq 0 ]]; then
    VWIFI_IFACE=${WIFI_IFACE}ap
    # in NetworkManager 0.9.10 and above we can set the interface as unmanaged without
    # the need of MAC address, so we set it before we create the virtual interface.
    if networkmanager_is_running && [[ $NM_OLDER_VERSION -eq 0 ]]; then
    echo -n "Network Manager found, set $1 as unmanaged device... "
    networkmanager_add_unmanaged ${VWIFI_IFACE}
    # do not call networkmanager_wait_until_unmanaged because interface does not
    # exist yet
    echo "DONE"
    fi
    WIFI_IFACE_CHANNEL=$(iw dev ${WIFI_IFACE} info | grep channel | awk '{print $2}')
    if [[ -n $WIFI_IFACE_CHANNEL && $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then
    echo "hostapd will fail to use channel $CHANNEL because $WIFI_IFACE is already set to channel $WIFI_IFACE_CHANNEL, fallback to channel $WIFI_IFACE_CHANNEL."
    CHANNEL=$WIFI_IFACE_CHANNEL
    fi
    VIRTDIEMSG="Maybe your WiFi adapter does not fully support virtual interfaces.
    Try again with --no-virt."
    echo -n "Creating a virtual WiFi interface... "
    iw dev ${VWIFI_IFACE} del > /dev/null 2>&1
    if iw dev ${WIFI_IFACE} interface add ${VWIFI_IFACE} type __ap; then
    # now we can call networkmanager_wait_until_unmanaged
    networkmanager_is_running && [[ $NM_OLDER_VERSION -eq 0 ]] && networkmanager_wait_until_unmanaged ${VWIFI_IFACE}
    echo "${VWIFI_IFACE} created."
    else
    VWIFI_IFACE=
    die "$VIRTDIEMSG"
    fi
    OLD_MACADDR=$(get_macaddr ${VWIFI_IFACE})
    [[ ${OLD_MACADDR} == $(get_macaddr ${WIFI_IFACE}) ]] && NEW_MACADDR=$(get_new_macaddr ${VWIFI_IFACE})
    WIFI_IFACE=${VWIFI_IFACE}
    fi
    can_transmit_to_channel ${WIFI_IFACE} ${CHANNEL} || die "Your adapter can not transmit to channel ${CHANNEL}."
    if networkmanager_is_running && ! networkmanager_iface_is_unmanaged ${WIFI_IFACE}; then
    echo -n "Network Manager found, set $1 as unmanaged device... "
    networkmanager_add_unmanaged ${WIFI_IFACE}
    networkmanager_wait_until_unmanaged ${WIFI_IFACE}
    echo "DONE"
    fi
    [[ $HIDDEN -eq 1 ]] && echo "Access Point's SSID is hidden!"
    # hostapd config
    cat << EOF > $CONFDIR/hostapd.conf
    ssid=${SSID}
    interface=${WIFI_IFACE}
    driver=${DRIVER}
    hw_mode=g
    channel=${CHANNEL}
    ctrl_interface=$CONFDIR/hostapd_ctrl
    ctrl_interface_group=0
    ignore_broadcast_ssid=$HIDDEN
    EOF
    if [[ $IEEE80211N -eq 1 ]]; then
    cat << EOF >> $CONFDIR/hostapd.conf
    ieee80211n=1
    wmm_enabled=1
    ht_capab=${HT_CAPAB}
    EOF
    fi
    if [[ -n "$PASSPHRASE" ]]; then
    [[ "$WPA_VERSION" == "1+2" || "$WPA_VERSION" == "2+1" ]] && WPA_VERSION=3
    cat << EOF >> $CONFDIR/hostapd.conf
    wpa=${WPA_VERSION}
    wpa_passphrase=$PASSPHRASE
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP CCMP
    rsn_pairwise=CCMP
    EOF
    fi
    if [[ "$SHARE_METHOD" == "bridge" ]]; then
    echo "bridge=${BRIDGE_IFACE}" >> $CONFDIR/hostapd.conf
    else
    # dnsmasq config (dhcp + dns)
    DNSMASQ_VER=$(dnsmasq -v | grep -m1 -oE '[0-9]+(\.[0-9]+)*\.[0-9]+')
    version_cmp $DNSMASQ_VER 2.63
    if [[ $? -eq 1 ]]; then
    DNSMASQ_BIND=bind-interfaces
    else
    DNSMASQ_BIND=bind-dynamic
    fi
    cat << EOF > $CONFDIR/dnsmasq.conf
    interface=${WIFI_IFACE}
    ${DNSMASQ_BIND}
    dhcp-range=${GATEWAY%.*}.1,${GATEWAY%.*}.254,255.255.255.0,24h
    dhcp-option=option:router,${GATEWAY}
    EOF
    [[ $ETC_HOSTS -eq 0 ]] && echo no-hosts >> $CONFDIR/dnsmasq.conf
    fi
    # initialize WiFi interface
    if [[ $NO_VIRT -eq 0 && -n "$NEW_MACADDR" ]]; then
    ip link set dev ${WIFI_IFACE} address ${NEW_MACADDR} || die "$VIRTDIEMSG"
    fi
    ip link set down dev ${WIFI_IFACE} || die "$VIRTDIEMSG"
    ip addr flush ${WIFI_IFACE} || die "$VIRTDIEMSG"
    if [[ "$SHARE_METHOD" != "bridge" ]]; then
    ip link set up dev ${WIFI_IFACE} || die "$VIRTDIEMSG"
    ip addr add ${GATEWAY}/24 broadcast ${GATEWAY%.*}.255 dev ${WIFI_IFACE} || die "$VIRTDIEMSG"
    fi
    # enable Internet sharing
    if [[ "$SHARE_METHOD" != "none" ]]; then
    echo "Sharing Internet using method: $SHARE_METHOD"
    if [[ "$SHARE_METHOD" == "nat" ]]; then
    iptables -t nat -I POSTROUTING -o ${INTERNET_IFACE} -j MASQUERADE || die
    iptables -I FORWARD -i ${WIFI_IFACE} -s ${GATEWAY%.*}.0/24 -j ACCEPT || die
    iptables -I FORWARD -i ${INTERNET_IFACE} -d ${GATEWAY%.*}.0/24 -j ACCEPT || die
    echo 1 > /proc/sys/net/ipv4/ip_forward || die
    elif [[ "$SHARE_METHOD" == "bridge" ]]; then
    # disable iptables rules for bridged interfaces
    echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables || die
    # create and initialize bridged interface
    brctl addbr ${BRIDGE_IFACE} || die
    brctl addif ${BRIDGE_IFACE} ${INTERNET_IFACE} || die
    ip link set dev ${BRIDGE_IFACE} up || die
    fi
    else
    echo "No Internet sharing"
    fi
    # boost low-entropy
    if [[ $(cat /proc/sys/kernel/random/entropy_avail) -lt 1000 ]]; then
    which haveged > /dev/null 2>&1 && {
    haveged -w 1024 -p $CONFDIR/haveged.pid
    fi
    # start dns + dhcp server
    if [[ "$SHARE_METHOD" != "bridge" ]]; then
    iptables -I INPUT -p tcp -m tcp --dport 53 -j ACCEPT || die
    iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT || die
    iptables -I INPUT -p udp -m udp --dport 67 -j ACCEPT || die
    dnsmasq -C $CONFDIR/dnsmasq.conf -x $CONFDIR/dnsmasq.pid || die
    fi
    # start access point
    echo "hostapd command-line interface: hostapd_cli -p $CONFDIR/hostapd_ctrl"
    # from now on we exit with 0 on SIGINT
    trap "clean_exit" SIGINT
    if ! hostapd $CONFDIR/hostapd.conf; then
    echo -e "\nError: Failed to run hostapd, maybe a program is interfering." >&2
    if networkmanager_is_running; then
    echo "If an error like 'n80211: Could not configure driver mode' was thrown" >&2
    echo "try running the following before starting create_ap:" >&2
    if [[ $NM_OLDER_VERSION -eq 1 ]]; then
    echo " nmcli nm wifi off" >&2
    else
    echo " nmcli r wifi off" >&2
    fi
    echo " rfkill unblock wlan" >&2
    fi
    die
    fi
    clean_exit
    Last edited by OBLiQUE (2014-09-02 20:26:22)

    adam777 wrote:
    Thank, just what I was looking for.
    Unfortunately, it seems that currently my Intel 5300 card (using the iwlwifi driver), does not support AP mode.
    From what I understand, hostapd can be used in bridge mode as well, which should have no compatibility problems.
    Can some one point me in the right direction?
    * EDIT *
    After more attempts, I think I got it wrong and AP mode is indeed required.
    Sorry for the late reply, I didn't noticed your message.. Did you got any errors? I have Intel 6205 and it works.
    Also if you use NetworkManager, then you have to say to NetworkManager to stop using your interface.
    You can do it by editing the /etc/NetworkManager/NetworkManager.conf file and put the following (without the <>):
    [keyfile]
    unmanaged-devices=mac:<interface's mac address here>
    and restart your NetworkManager. Ofcourse after you finish, you have to remove it in order to get your wifi back to working with NetworkManager.

  • Script to force WiFi release - Guest account

    Hi.
    I am desperately trying to find a script solution to solve a network problem i am having.
    We have 4 public computers at a school "public area" (for students). We have created a
    guest account that works satisfactory except for one thing, the wifi stays logged on
    even if the account is logged out.
    Each student has to log on using a web service in order to gain access to Internet.
    This works great but when the student logs out of the guest account and a new student
    opens the same account the Internet is still available using the first users id.
    Does any one have a soulution for this ?
    /Martin

    Apple allows you to write a logout hook.
    See:
    http://chris-mccafferty.blogspot.com/2010/12/mac-os-x-login-and-logout-scripts.h tml
    also:
    http://www.macos.utah.edu/documentation/programming_and_scripting/login_and_logo ut_scripts/mainColumnParagraphs/00/document/20030219-Scripts.pdf

  • Script to turn wifi on/off

    Hello,
    Can someone provide a script that will simply turn on or off wifi as if using doing this manually from the menu bar?
    THx!

    Thanks for this. I did google and find a few others before I posted but none of them worked.
    This one did work http://www.makiaea.org/post/5993587804 after I changed "en0" to "en1"
    THis is working in my MBP:
    -- 20110529 www.makiaea.org ref: 20110529wlx-wirelessonoff.applescript
    -- wlx toggles wifi (airport wireless) power on and off
    -- Tested using macbook air 3,1 , mac os 10.7 (Build 11A459e), quicksilver ß59 (3842)
    -- if you are not using quicksilver to run the script, you may need to compile the script first (using applescript editor) and save as an .scpt script or as an app if you want to double–click with the mouse on an icon to run it.
    -- note this assumes your wireless ethernet interface is en1
    -- get the correct interface from the menu Apple|About This Mac|Network|Wi-Fi or from terminal using ifconfig -a
    try
              set makiaeawirelessstatus to do shell script "networksetup -getairportpower en1"
    on error
              display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}
    end try
    if makiaeawirelessstatus is "Wi-Fi Power (en1): On" then
              do shell script "networksetup -setairportpower en1 off"
    else if makiaeawirelessstatus is "Wi-Fi Power (en1): Off" then
              do shell script "networksetup -setairportpower en1 on"
    else
              display dialog "The script did not work as intended, please check your wireless connection is specified correctly. The default in this script is en1 (please open the applescript in applescript editor for more details)" buttons {"kthxbai"}
    end if
    THx

  • Script to fight buggy WiFi access points

    This is a script that implements automatic reconnect to WiFi access points. It's called hold-connect. It uses netcfg as backend, so any other connection types are also supported (like PPP link). It had been tested every day for 2 months with a buggy public wifi router (its DHCP server quite often failed).
    Features:
    - Checking of internet connection via host pinging with 1 packet;
    - Reconnecting if link failure is detected;
    - Informative output;
    - Customizable hostname, check interval and retry count.
    Dependencies:
    - bash;
    - netcfg 2.5.4;
    - optional: configured sudo. To run from root, all "sudo" strings can be safely removed.
    Syntax is simple:  hold-connect netcfg_profile_name . Also some parameters can be customized inside script (follow comments). Therefore it's advised to keep script file somewhere like /home/user and place a symlink to it in /usr/bin.
    Usage: start and enjoy! To stop it, simply kill it with ^C or kill -15.
    hold-connect.sh:
    #!/bin/bash
    # hold-connect - simple script to hold wifi link up in hard conditions.
    # Version: 060710
    # USAGE:
    # hold-connect profile_name
    # Profile name is a valid netcfg profile used to reconnect.
    # Return values:
    # 0 - happens only when script runs more than infinite time :-)
    # 1 - error in arguments
    # 2 - error while connecting
    # Adjustable constants are here:
    TEST_URL="qrz.ru" # URL to check via pinging
    CHECK_INTERVAL=30 # Network status checking interval, in seconds (default: 30)
    RETRY_LIMIT=3 # Maximum number of retries (default: 3)
    connect()
    sudo netcfg down $CURRENT_PROFILE > /dev/null 2>&1
    RETRY_COUNT=0
    CONN_STAT="" # Trigger the cycle at start
    while [ -z "`echo $CONN_STAT | grep DONE`" ]; do
    if [ -n "$CONN_STAT" ]; then
    echo "[`date +%H:%M:%S`] Failed to connect using $CURRENT_PROFILE, trying again"
    fi
    CONN_STAT="`sudo netcfg $CURRENT_PROFILE`"
    if [ -n "`echo $CONN_STAT | grep "Association Failed"`" ]; then
    if [ $RETRY_COUNT != $RETRY_LIMIT ]; then
    echo "Access point unreachable"
    RETRY_COUNT=$((RETRY_COUNT+1))
    else
    echo "More than $RETRY_LIMIT sequental errors, exiting"
    exit 2
    fi
    else RETRY_COUNT=0; # reset if error is not sequental
    fi
    sleep 2
    done
    # Check if there's no parameters
    if [ -z $1 ]; then
    echo "hold-connect: no profile specified"
    echo "Usage:"
    echo " hold-connect profile_name"
    exit 1
    fi
    # Check if profile exists
    if [ -z `sudo netcfg -l | grep -x $1` ]; then
    echo "hold-connect: profile $1 does not exist"
    exit 1
    fi
    CURRENT_PROFILE=$1
    echo "hold-connect 060710, using profile $CURRENT_PROFILE and test URL $TEST_URL"
    while [ "1" ]; do
    while [ -z "`ping -c 1 $TEST_URL 2> /dev/null`" ]; do # to be sure that netcfg isn't wrong
    echo "No connect to $TEST_URL, raising $CURRENT_PROFILE"
    connect
    done
    echo "[`date +%H:%M:%S`] *** Connection to $TEST_URL is up"
    sleep $CHECK_INTERVAL
    done

    Ignore my above post. It is just plane stupid and you cant stop or restart  the daemon.
    Heres howit should look like:
    /usr/bin/hold-connect:
    #!/bin/bash
    # hold-connect - simple script to hold wifi link up in hard conditions.
    # Version: 060710
    # USAGE:
    # hold-connect profile_name
    # Profile name is a valid netcfg profile used to reconnect.
    # Return values:
    # 0 - happens only when script runs more than infinite time :-)
    # 1 - error in arguments
    # 2 - error while connecting
    # Adjustable constants are here:
    TEST_URL="qrz.ru" # URL to check via pinging
    CHECK_INTERVAL=30 # Network status checking interval, in seconds (default: 30)
    RETRY_LIMIT=3 # Maximum number of retries (default: 3)
    connect()
    sudo netcfg down $CURRENT_PROFILE > /dev/null 2>&1
    RETRY_COUNT=0
    CONN_STAT="" # Trigger the cycle at start
    while [ -z "`echo $CONN_STAT | grep DONE`" ]; do
    if [ -n "$CONN_STAT" ]; then
    echo "[`date +%H:%M:%S`] Failed to connect using $CURRENT_PROFILE, trying again" >> /var/log/hold-connect.log
    fi
    CONN_STAT="`sudo netcfg $CURRENT_PROFILE`"
    if [ -n "`echo $CONN_STAT | grep "Association Failed"`" ]; then
    if [ $RETRY_COUNT != $RETRY_LIMIT ]; then
    echo "Access point unreachable" >> /var/log/hold-connect.log
    RETRY_COUNT=$((RETRY_COUNT+1))
    else
    echo "More than $RETRY_LIMIT sequental errors, exiting" >> /var/log/hold-connect.log
    exit 2
    fi
    else RETRY_COUNT=0; # reset if error is not sequental
    fi
    sleep 2
    done
    # Check if there's no parameters
    if [ -z $1 ]; then
    echo "hold-connect: no profile specified"
    echo "Usage:"
    echo " hold-connect profile_name"
    exit 1
    fi
    # Check if profile exists
    if [ -z `sudo netcfg -l | grep -x $1` ]; then
    echo "hold-connect: profile $1 does not exist"
    exit 1
    fi
    CURRENT_PROFILE=$1
    echo "hold-connect 060710, using profile $CURRENT_PROFILE and test URL $TEST_URL" >> /var/log/hold-connect.log
    while [ "1" ]; do
    while [ -z "`ping -c 1 $TEST_URL 2> /dev/null`" ]; do # to be sure that netcfg isn't wrong
    echo "No connect to $TEST_URL, raising $CURRENT_PROFILE" >> /var/log/hold-connect.log
    connect
    done
    echo "[`date +%H:%M:%S`] *** Connection to $TEST_URL is up" >> /var/log/hold-connect.log
    sleep $CHECK_INTERVAL
    done
    /etc/rc.d/hold-connect:
    #!/bin/bash
    . /etc/rc.conf
    . /etc/rc.d/functions
    CURRENT_PROFILE="korvmedmos" # Network profile to use
    DIE=`ps alx | grep hold-connect | grep -v "grep" | awk '{ print $3 }'`
    case "$1" in
    start)
    stat_busy "Starting hold-connect"
    /usr/bin/hold-connect $CURRENT_PROFILE & > /dev/null 2>&1
    if [ $? -gt 0 ]; then
    stat_fail
    else
    add_daemon hold-connect
    stat_done
    fi
    stop)
    stat_busy "Stopping hold-connect"
    rm_daemon ntpdate
    stat_done
    kill $DIE
    restart)
    $0 stop
    sleep 1
    $0 start
    echo "usage: $0 {start|stop|restart}"
    esac
    I need more brainzzz. Please give!
    Last edited by whacath (2010-09-16 18:11:16)

  • Run a script on wifi network change

    hello,
    I've been trying to figure out how to run a simple shell/python script whenever my mac's wifi network changes. After some extensive googling, I found that OS 10.5 had a utility called "kicker," but that it was removed in 10.6.
    How would I go about setting up my script to run on a change in wifi network?
    Thanks--
    --Jordan

    I've been trying to figure out how to run a simple shell/python script whenever my mac's wifi network changes. After some extensive googling, I found that OS 10.5 had a utility called "kicker," but that it was removed in 10.6.
    My Mac OS X 10.5.8 system does NOT have a program called 'kicker' anywhere on the system.
    How would I go about setting up my script to run on a change in wifi network?
    MacroPolo is most likely the easiest solution. After that my previously suggested SleepWatcher or a launchd "WatchPaths".

  • I have OSX 10.7 Lion I set up a separate email account for my wife.  Now when she tries to enter a website we get the following error message:  Java Script: Not Null validator already loaded.  The website never opens and it is difficult to get out of:

    I have OSX 10.7 Lion.  I set up a separate email account for my wife.  All of a sudden when she tries to enter and website from email we get the following error message.  JavaScript;  The notnull validator has already been loaded.  From there we can't seem to go any where.  When you hit OK it just keeps appearing and the only way to get out of it is to quit Safai.  If you try and got directly to Safari you get the same error message and can't go any further.  Please help.

    What you are experiencing is 100% related to Malware.
    Sometimes a problem with Firefox may be a result of malware installed on your computer, that you may not be aware of.
    You can try these free programs to scan for malware, which work with your existing antivirus software:
    * [http://www.microsoft.com/security/scanner/default.aspx Microsoft Safety Scanner]
    * [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware]
    * [http://support.kaspersky.com/faq/?qid=208283363 TDSSKiller - AntiRootkit Utility]
    * [http://www.surfright.nl/en/hitmanpro/ Hitman Pro]
    * [http://www.eset.com/us/online-scanner/ ESET Online Scanner]
    [http://windows.microsoft.com/MSE Microsoft Security Essentials] is a good permanent antivirus for Windows 7/Vista/XP if you don't already have one.
    Further information can be found in the [[Troubleshoot Firefox issues caused by malware]] article.
    Did this fix your problems? Please report back to us!

  • [solved] Making stuff run during boot (wifi connect script)

    In Ubuntu, I used some commands to add a script to init.d for a wireless connect script, but Arch is differnet. How would I go about putting a script to connect to wireless during startup? (GUI network managers don't like me, and if they don't connect quick enough, then Kopete complains )
    Last edited by doorknob60 (2008-09-30 01:11:18)

    Nice, it worked perfectly, and I didn't even notice it boot slower I was getting tired of manually connecting after logging in.

  • Can I add a wifi profile in profilemanager by script

    We want to add a profile file in profile manager on lion server automaticlly by scriipt or some api interface, not use the profilemanger program setup, which interface can we use to call?

    Does the new Airport Extreme support WPS-capable printing?
    Yes
    Does AirPort Utility 6.3 support it?
    Yes

  • How to view videos stored in home imac on iPod or iPad over wifi

    hello;
    Using the web server on the iMac there is a easy way
    to view stored videos on the iPod or iPad. When I say 'easy'
    I consider it easy, you may not find it 'easy'.
    The most low tech way is to create a symbolic link from the video file
    to the /Library/WebServer/Documents/ directory.
    example:
    open a terminal window.
    create a symbolic link from the video file on the iMac to the /Library/WebServer/Documents/
    sudo ln -s <iTunes Library Directory>/TV Shows/<TV Show Name>/<TV Season>/<TV Episode> video-link-01
    To view the video on either an iPod, iPad, or another computer in Safari
    you would enter the following:
    http://<computer-name.local>/video-link-01
    The video will be shown by QuickTime plugin in Safari...
    I have written a perl script which I use to create the necessary html files
    to view all the TV Shows that I have stored on my iMac. You could also
    create these using a text editor like vim or textedit.
    The index.html lists the TV Shows in alphabetical order.
    For each TV Show there is a corresponding html file which list the seasons.
    For each TV Show Season there is a corresponding html file which lists the episodes.
    Below is a short example.
    sudo cd /Library/WebServer/Documents
    sudo ln -s /Users/me/Music/iTunes/iTunes\ Music/TV\ Shows ./TV\ Shows
    the index.html file contains:
    <begin quote>
    <html version="2.0">
    <head>
    <title>iTunes TV Shows - 05 May 2010</title>
    </head>
    <body>
    <center>
    <a href="./Doctor-Who.html">Doctor Who</a>
    <br><br>
    </center>
    </body>
    </html>
    <end quote>
    The Doctor-Who.html file contains:
    <begin quote>
    <html version="2.0">
    <head>
    <title>iTunes TV Shows - Doctor Who - 05 May 2010</title>
    </head>
    <body>
    <center>
    <a href="Doctor-Who-Season-1.html">Doctor Who - Season 1</a>
    <br><br>
    <a href="Doctor-Who-Season-2.html">Doctor Who - Season 2</a>
    <br><br>
    <a href="Doctor-Who-Season-3.html">Doctor Who - Season 3</a>
    <br><br>
    <a href="Doctor-Who-Season-4.html">Doctor Who - Season 4</a>
    <br><br>
    </center>
    </body>
    </html>
    <end quote>
    The Doctor-Who-Season-4.html file contains:
    <being quote>
    <html version="2.0">
    <head>
    <title>iTunes TV Shows - Doctor Who - Season 4 - 05 May 2010</title>
    </head>
    <body>
    <center>
    <a href="TV Shows/Doctor Who/Season 4/1-01 Voyaged of the Damned.m4v">1-01 Voyaged of the Damned.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/2-02 Partners in Crime.m4v">2-02 Partners in Crime.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/2-03 The Fires of Pompeii.m4v">2-03 The Fires of Pompeii.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/2-04 Planet of the OOD.m4v">2-04 Planet of the OOD.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/3-05 The Sontarian Stratagem.m4v">3-05 The Sontarian Stratagem.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/3-06 The Poisin Sky.m4v">3-06 The Poisin Sky.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/3-07 The Doctors Daughter.m4v">3-07 The Doctors Daughter.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/3-08 The Unicorn and the Wasp.m4v">3-08 The Unicorn and the Wasp.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/4-09 Silence in the Library.m4v">4-09 Silence in the Library.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/4-10 Forest of the Dead.m4v">4-10 Forest of the Dead.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/4-11 Midnight.m4v">4-11 Midnight.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/5-12 Turn Left.m4v">5-12 Turn Left.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/5-13 The Stolen Earth.m4v">5-13 The Stolen Earth.m4v</a>
    <br><br>
    <a href="TV Shows/Doctor Who/Season 4/5-14 Journeys End.m4v">5-14 Journeys End.m4v</a>
    <br><br>
    </center>
    </body>
    </html>
    <end quote>
    The same may be done for movies and music.
    I am working on coming up with a way to play an entire musical album and playlist.
    Right now it is single songs only which tends to limit its usefulness.
    For videos it does work extremely well. Even though I have a 64GB iPad, a 64GB iPod touch, a 32GB iPod touch, a 32GB iPod touch( 1st generation), and an 16GB iPod nano I do not have to sync a video to them in order to be able to view the video.
    I am able to sit in my favorite Caribou Coffee Shop and watch the latest TV shows I have purchased on iTunes
    over the wifi network.
    Suggestions are to use the Standard Definition file and not the High Definition file.
    I personally cannot tell the difference between the Standard Definition file and the High Definition file
    on the iPods or the iPad.
    I hope that helps you to enjoy your iPods, iPhones, and iPads.
    terry ><>

    Have you looked at the previous discussions listed on the right side of this page under the heading "More Like This"? Ones with a green checkmark are solved.
    Next Google for: rotate iphone videos

Maybe you are looking for

  • CRM orders with error "Do not enter a business agreement for sold-to party"

    Dear SDN'ler, after creating orders in SAP CRM via ISA (CRM 4.0) and uploading them to R/3 all orders are created successfully in R/3 but an error message is sent back to SAP CRM in case of ALL orders. Error message is the following: "Do not enter a

  • How to add arguments in java command

    hi All, I am using ant for calling java command. How do I add more than 1 argument for <arg> tag ?. <target name="A" depends="prepare" description="Starts the client" > <java classname="Starter" fork="yes"> <args>      <arg value="${clientArg1}"/>   

  • Removing an Application Module form the Pool in a JSP Page

    I am getting the following error: JBO-30003: The application pool (dpi.src.business.srcSchReportAppModule.srcSchReportAppModuleLocal) failed to checkout an application module due to the following exception: oracle.jbo.DMLException: JBO-26066: Error d

  • Replicating data from SQL Server to Oracle

    I like to know whether it is possible to Replicate data from SQL Server to Oracle and vice-versa. My present application is using SQL server and very recently we migrated to Oracle. As the usage of SQL Server is more, I like to replicate the data bei

  • Jobs are not in active state

    Jobs are in Ready stage but it is not going to active what might me the problem. could any one can reply to my question.