Auto relogin cron script to captive portal on wlan client interface

auto relogin cron script to captive portal on wlan client interface

in cron: (crontab -e) or Scheduled Tasks
* * * * * /etc/crontabs/captive-login.sh

in /etc/crontab/captive-login.sh with chmod 755 captive-login.sh

#!/bin/sh

# captive-login.sh	auto relogin to captive portal on wlan client interface
#
# ping captive portal, not reachable => restart wlan
# ping internet address, not reachable => login to captive portal

# logger "captive-login: auto relogin to captive portal by wlan"

# url or id-adress of the captive portal
url_cp=<xxx.xxx.xxx.xxx>
# login-link to the captive portal
url_cp_login=<https:/yyyyy.com/yyyy>
# url or ip-adress of an internet server
url_net=8.8.8.8

# ping captive portal
return_text=$(ping -c 2 -W 4 $url_cp)
return_value=$?
# logger "captive-login: PING VALUE: $return_value; PING TEXT: $return_text"
case $return_value in
	0)	;;
	1)	wifi down radio0
		logger "captive-login: reconnect wlan"                                                                                             
                sleep 5s                                                                                                         
                wifi up radio0                                                                                              
                sleep 5s     
		;;
	*)	;;
esac

# ping internet address
return_text=$(ping -c 2 -W 4 $url_net)
return_value=$?
case $return_value in
	0)	;;
	1)	wget $url_cp_login -0 /dev/null
		logger "captive-login: login"
		;;
	*)	;;
esac

I am still testing, if this runs well in all situations.
It should be improved in situations of fails.

Peter

This script has several problems and it is a bad idea to call it every minute ... I will improve it and repost it.

Peter

I think the "travelmate" package could be a source of inspiration here.

1 Like

Thank You eduperez.

In https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md

Installation & Usage

(...)

  • configure your network:
    (...)
    • at least you need one configured AP and one STA interface

wireless hotspot/station (STA)
wireless access point (AP)

I do not want to configure an AP, the traffic should be routed into my LAN.

Travelmate needs scripts written by myself to reconnect to the captive portals. I guess it will be less work for me to write a small script without travelmate.

Anyway I will test travelmate.

Peter

1 Like