Automatically refreshing my WiFi connection via a script?
In AppleScript use: do shell script "networksetup -setairportpower en0 off; sleep 2; networksetup -setairportpower en0 on" although you might have to change en0 to the appropriate adapter which you can get from the Network Utility.

If you want it in a BASH script don't use the do shell script part and the rest can be on one line or remove the ; adding a newline in there place.  You could swap the display dialog ... in Buscar웃's script with this if you want.