Jump to content

Check To See If Internet Is Available


DavidAM

Recommended Posts

My Internet connection seems to be problematic right now. So, I decided to write a script to run continuously and periodically check to see if the Internet is available. The script checks every five minutes (which is configurable, and I might want to change to 1 minute or 15 minutes).

 

So, my question is, what is a good way to check to see if the Internet is available. My first thought was to do a DNS lookup. So I tried using dig +short domainname which works, and responds pretty quickly. I'm just concerned that a DNS lookup every minute is going to get me "on the radar", so to speak. It does not seem excessive from a network standpoint, but I have no real experience on that side and don't know what Network Admins might be watching for; or if DNS results might be cached in the router or modem (it does not appear to be, but I am guessing).

 

I am also wondering if there is a different command I can (or should) use.

 

The configuration is:

Debian Linux <----CAT5----> NetGear (Wireless) Router <----CAT5----> Cisco Cable Modem <----Cable----> Internet

 

So checking to see if the network is up will always return success (unless the router is down). But I want to know if The Internet is available.

 

As long a I am doing this, I wouldn't mind adding a check on the router as well, so if there is a good way to do that, I would be interested to know. For now, the script is written in PHP; I can switch to bash or even a C program if I need to (although, I would like to keep it as a script).

Link to comment
Share on other sites

We had kind of spotty internet for a while and what I did was setup something to ping my ISP's dns servers a few times every hour. I don't think a few pings every couple minutes or a couple DNS lookups would cause any issues, probably nobody would even notice.

 

If I were going to setup something again I'd probably ping my linode VPS (or just try and wget the homepage) to test for a connection.

 

Trying to hit some external device is really about the only effective way to test. You just need to decide what device, how to hit it, and how often.

 

Link to comment
Share on other sites

If the problem is the first hop between your modem and the ISP then you can do a tracert/traceroute with a maximum number of hops being (the distance between your machine and the modem/router) + 1.

But really, a ping to someplace you know should always be up is just as good - and much easier to implement.

Link to comment
Share on other sites

Thanks for the suggestions. I wasn't sure if there was some "magic" C library somewhere that could read something from the NIC card. I think I'll just stick with the DNS lookup. I've given it an array of domains I use regularly, and are not likely to go away. I rotate through the list, mostly because I wasn't sure if the router would cache anything. I don't think it does though. If I disconnect the router from the modem, it fails immediately.

 

I am running dig +short domainname. Which prints a single line containing the IP address, and exits with a status of zero. I've noticed that if I disconnect the router, it still exits with zero, but does not output anything. If I shutdown the modem, it exits with a status of 9, and prints a message about the failure.

 

I had the cable guys out today. They replaced several of the "F" connectors throughout the house, and told me that the cable in the wall that the modem is plugged into has some noise on it. They offered to replace it, at a cost of $50. I told them I'd do it myself. I'm pretty sure we have a spool of RG-6 at the shop, and one or two of my guys are capable of crimping it. Pulling it down the wall will not be a problem. The network is still bouncing up and down more than I like -- 8 times in the past 6 hours for a total of 50 times today (since midnight). Well, we will see what happens when I replace the cable tomorrow.

Link to comment
Share on other sites

Did he tell you, or do you know how many splitters are between the modem and the main line? We had a problem with our on-demand on the TV not working after moving into this place. I was able to re-route the cable to only go through one splitter by the main line and that solved the issue. Could cause issues with modems too if there are a couple in the path. Definitely shouldn't be too hard to run a new cable though if that is what it takes to get things fixed up.

Link to comment
Share on other sites

Yeah, I went through the "too many splitters" issue a couple of years ago. At that time there were two. The guy then re-routed one of the cables and there is now only one splitter; its a 4-way splitter in the house. It did make a difference at the time, but things have progressively gotten worse; both with the on-demand and the Internet.

 

I don't know much about the hardware side of things, but everything he said makes sense. I've got a guy at work that knows the cable side pretty well, he's been out all day on a job, so I haven't been able to talk to him, yet.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.