views:

1742

answers:

6

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?

+7  A: 
Silfverstrom
+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
Why reinvent the wheel? curl and wget both do this perfectly.
Adam Rosenfield
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
Yeah, telnetting has been a pretty standard way to test connections for quite a while.
PTBNL
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
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
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
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
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