Batch File to Maintain Wireless Connection

This is a Windows batch file and a hack for working around intermittent wireless disconnects. If your connection periodically goes to “no internet access”, this script may help. Obviously, it would be better to find and fix the problem but this may keep you going until you do.

This seems so easy that there must be something wrong with it, but I don’t know what that is yet, so I don’t promise anything. It works for me and I can even keep a putty session going with this script running despite frequent intermittent disconnects.

My script figures out the default gateway and the SSID. It pings the default gateway and upon failure, it will reconnect using the SSID. Then it waits 30 seconds and starts over.

I came up with this script after finding plenty of scripts that were pretty close but not quite what I wanted. Some required that you figure out the default gateway and/or the ssid before running the script. Some required the name of the interface. I wanted something that didn’t require my input.

This will open a command window. The command window reports when a reconnection was required and also allows you to hit a key to bypass the 30 second wait period for one round.


@setlocal enableextensions enabledelayedexpansion
@echo off
:loop
for /f "tokens=3 delims= " %%a in ('netsh wlan show interfaces ^| findstr "^....SSID"') do (
set ssid=%%a
)
for /f "tokens=13 delims= " %%a in ('ipconfig ^| findstr "Default.Gateway.*[0-9]"' ) do (
set gateway=%%a
)
ping -n 1 %gateway% | find "TTL="
if errorlevel 1 (
goto :reset
) else (
@timeout /t 30
goto :loop
)
:reset
time /T
netsh wlan connect %ssid%
@timeout /t 60
goto :loop
endlocal

Advertisements

Cable Signal Loss Causes Modem to Disconnect Router

I’m crowd sourcing this among the three or four people who read this blog. And it might help someone who’s experiencing similar symptoms.

If you’re experiencing intermittent disconnects between your modem and router, it may be a problem with your incoming signal.

It makes no sense to me either, but when my cable modem loses the signal from my provider it disconnects the router. The router’s status changes from “connected” to “connecting”, and of course the modem’s status page is inaccessible from wireless network. What I thought was a problem between the modem and router was actually caused by a poor signal from the provider. It’s a Motorola Surfboard and a Medialink router, but this also happened with a Cisco modem which the cable company replaced and old Cradlepoint modem.

Any ideas why this might happen?

Wireless with Dell E1505 and Ubuntu 9.10

I use a Dell Inspiron E1505 with a Broadcom BCM4311 wireless card. Before I upgraded to Ubuntu 9.10, I was using ndiswrapper and connecting with a script that I adapted from the popular wirelessfix.sh script. I did not use Gnome’s NetworkManager; in fact, I couldn’t get it to work with my configuration. I like using the command line to control my computer, but when I tried to connect to a wireless network that required a passphrase, I was unable to figure it out.

I upgraded to 9.10 (Karmic Koala) just a couple of days ago. Upgrade might be the wrong word. I partitioned my hard disk, installed Ubuntu 9.10 from a CD which I got from a paper copy of Linux Pro, then copied what I needed and deleted the old Ubuntu. The installation went smoothly. After installation, I found these instructions, which seemed too easy to be true considering some of the other advice for wireless that is currently on the web. In fact it was even easier. I was able to load bcmwl-kernel-source from the CD using Synaptic Package Manager, and the other files installed as dependencies. I did not have to install ndiswrapper.

Now my wireless connections are handled with ease, and network manager even displays a dialog when a passphrase is called for. I’m a little sad about relinquishing control to an automatic system, but it works well.

This, along with some other improvements, makes 9.10 a very good upgrade.
.

Modified wirelessfix.sh

I don’t know who originated the bash script called wirelessfix.sh, but it’s great solution to common ndiswrapper problems. Thank you.

I expanded on it. With my version if I pass a parameter to the script, it will set the essid to the parameter that I passed. If I run the script without the parameter, it will bring up a less screen with the results of “iwlist eth1 scan”, and upon exit from less will request an essid. Often, I copy the essid from the less page and past it when I exit less. Either way , it will bring up the interface with the essid.

Here’s my wirelessfix.sh:
Note1: In myscript, I commented out “modprobe b44” because it wasn’t doing anything for me. You might need it.
Note2: My interface is eth1. Yours might be different.

#!/bin/bash
ifdown eth1
modprobe -r b44
modprobe -r b43
modprobe -r b43legacy
modprobe -r ssb
modprobe -r ndiswrapper
modprobe ndiswrapper
# removed: modprobe b44
if [ -n “$1” ]; then
sudo iwconfig eth1 essid $1
else
iwlist eth1 scan | less
read -p essid: essid
sudo iwconfig eth1 essid $essid
fi
ifup eth1

Adding WEP key with iwconfig

Using Linux, with ndiswrapper for the wireless card, and using the command line to connect, I was having trouble connecting to a wireless access point with a WEP key until I put the keyword “open” in front of the string. If you’re pretty sure you’re entering the correct key and ESSID for a WEP encrypted access point, but still having trouble connecting, look at the man pages for iwconfig and see the examples under the section labeled “key/enc”. You’ll see the keyword “open” in one example and the keyword “restricted” in another. You might have to try each of these if you don’t know which to use. Although in the man pages, the “open” example doesn’t have a key, you can add the key just like in the “restricted” example.

example:
iwconfig eth1 essid MyAccessPoint key open c2fccef3d1

Marriage Saved by Cradlepoint!

My marriage is saved!

Our primary internet connection is through Verizon Wireless via a Sierra 595U usb aircard. It plugs into a usb port and provides internet service via a signal, called EVDO, which is similar to that of a cell phone. Most people get these because they want mobile internet access, but some people get them because they live in a land beyond cable and don’t have a lot of internet service options. That would be us. Using the aircard, we get decent connectivity, although not as good as real high speed, like DSL or cable.

The problem, until now, has been that it only plugs into one computer at a time. That means learning how to share, which can just kill a marriage. I tried to share using my own laptop as the access point, but that was a hassle (and also led to the previous post). I should add that my daughter usually connects via dial-up. Yes, dial-up. My son, for those who are wondering, doesn’t go online much and doesn’t have a computer.

So I finally ordered a cradlepoint ctr-350 from the 3Gstore. It arrived today and so far I am very happy with it. It is a wireless access point with a usb port that accepts an aircard, like our 595U. It is tiny; a little bigger than a deck of cards, and powered by a wall-wart about the size of a large cellphone charger. That’s small enough to take with us, should we ever travel together as a family (it could happen).

But the little box creates a usable area about as wide as that of most regular sized wireless routers. Although the specs don’t call out distance, I’ve read reviews saying it’s good for about 300 feet, and read one post from a person who said he connected from over 600 feet. So far, I’ve connected from a distance of over 50ft, and that distance is separated by a large storage trailer, essentially two big metal walls between the router and the laptop. The three of us have been online together and the signal seems to be good for all of us.

I was also impressed with the easy setup. I thought I was going to have to enter data about the aircard but it detected all the appropriate settings.

The new problem will be Verizon’s 5G per month limit. Now that we’re all online together though one aircard, we just might hit that limit. So unfortunately, we’ll still have to learn to share; either by managing a limited amount of gb or by pitching in to pay over-use charges.

The next marriage saving step is getting wireless connectivity at The Red Thread, where my wife sells yarn and often takes the aircard with her. And the signal just doesn’t go that far.