I have a D-Link Wi-Fi router that sometimes loses the PPPoE connection and thus requires reconnect. The standard way is to go to the web interface, login, and press the button. But it’s a long way, especially on an android device. Wouldn’t it be much nicer and faster to simply run a script?
I’ve installed busybox with the Busybox installer, and gotten wget, although very limited, it can’t send POST requests. curl is not there. So we’ll have to do with netcat. Here’s how to login:
Here, $BODY contains the form data which is sent in the POST body. We then calculate its length, because it’s required from the Content-Length HTTP header, as well as the Content-Type header. That’s what echo generates and sends to the socket:
The -i 3 parameter to nc is important because otherwise it doesn’t wait for a response. All in all, nothing special in this script, but gives an example how to send a POST with netcat. BTW, this may not be so easy with HTTP 2.0 if it’s going to be binary.
For the sake of completeness, you can find the scripts to restart the PPPoE connection for OS X, Linux, and Android below: