I'd like to be able to test if I have access to the internet. My computer is connected to the residence internet connection.
I thought of using
ping like this:
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error
But this does not work!
As I said the connection is provided by a residence(which is actually just forwarding the university connection). To have access to the internet you must open a web browser where you are requested user name and password and only then the internet access is granted.(I really have no clue about networks configurations etc. and anyway I do not have any access to how it is setup, so I can't provide more information on this side)
The above code prints "ok" even when I do not actually have access to the internet. Even testing with
www.google.com fails. I believe this is because it is being redirected to the login page and it "thinks" to get back the packets correctly.
How can I reliably check if I have access to the internet?
I'd like to connect to the computer in my room via
ssh when I go home during weekends. The connection sometimes fails so I'd like to create a script that every once in a while checks for the connection and eventually starts a web browser and sends keystrokes using
xdotool to login.
If you know a better way to reopen the connection to allow
ssh remote access than, please, write it too.
Some sample output of
$ nslookup unix.stackexchange.com Server: 127.0.1.1 Address: 127.0.1.1#53 Non-authoritative answer: Name: unix.stackexchange.com Address: 184.108.40.206
The result is exactly the same both with internet access and without it. (I've also tried to log off and relog, and connect and disconnect multiple times).
Also, I'd like to add that is not the
ssh connection closing.
For some time I'm able to create the connection, do things and log out. After some hours trying to do
ssh the-IP gives a timeout error(I actually registered a no-ip account since the IP is dynamic so I'm doing