How to test an internet connection without pinging to some website? I mean what if there are connection, but site is down, how to check that there is connection with world?
+2
A:
I've written scripts before that simply use telnet to connect to port 80, then transmit the text:
HTTP/1.0 GET /index.html
followed by two CR/LF sequences.
Provided you get back some form of HTTP response, you can generally assume the site is functioning.
paxdiablo
2009-05-30 08:50:24
Why reinvent the wheel? curl and wget both do this perfectly.
Adam Rosenfield
2009-05-31 02:51:23
Because wget and curl aren't always available (e.g., restrictions in corporate environments). Telnet has been a standard part of every UNIX since time t=0.
paxdiablo
2009-05-31 03:19:23
Yeah, telnetting has been a pretty standard way to test connections for quite a while.
PTBNL
2009-05-31 03:32:28
Good point, although wget is fairly common. Another option is netcat (nc), although in this case it's not any improvement over telnet.
Adam Rosenfield
2009-05-31 04:20:04
A:
If your local nameserver is down,
ping 4.2.2.1
is an easy-to-remember always-up IP (it's actually a nameserver, even).
ephemient
2009-05-31 02:43:52
A:
Ping your default gateway:
#!/bin/bash
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error
mateusza
2009-05-31 15:04:55
A:
Ping was designed to do exactly what you're looking to do. However, if the site blocks ICMP echo, then you can always do the telnet to port 80 of some site, wget, or curl.
nikudesu
2009-05-31 15:16:48
A:
Pong doesn't mean web service on the server is running; it merely means that server is replying to ICMP echo. I would recommend using curl and check its return value.
tbman
2009-06-02 13:55:25