Quick eth<->wifi script for OpenBSD lappy users

This is just a quick and dirty script I use on the new laptop, if you are interested. You will obviously need to convert this to your hardware and ensure your user has doas rights. I also have a symlink to this script in /usr/local/bin. This can be easily hacked to your liking for permanent IP’s, etc.

Good luck. Enjoy.

eth=em0
wifi=iwm0

doas ifconfig $eth down
doas ifconfig $wifi up
doas route -n flush

if [[ $1 == "search" ]]; then
	doas ifconfig $wifi scan
fi

if [[ $1 == "connect" ]]; then
	doas ifconfig $wifi nwid $2 wpa wpakey $3 wpaprotos wpa1,wpa2
	doas dhclient $wifi
fi

if [[ $1 == "disconnect" ]]; then
	doas ifconfig $wifi down
fi

if [[ $1 == "ethernet" ]]; then
	doas ifconfig $wifi down
	doas ifconfig $eth up
	if [[ $2 == "on" ]]; then
		doas dhclient $eth
	fi
	if [[ $2 == "off" ]]; then
		doas ifconfig $eth down
	fi
fi

Leave a Reply