|
-
Mar 26th, 2016, 08:06 AM
#1
Check Internet Connectivity
This is not for Network Engineers, they already know. (this is the biggest, most complicated network, that I designed and built)
My first piece of advice is don't bother checking, you can't predict the future. Consider the following,
Time
- You do some check, ping, etc. directed to "google.com" or some other host
- The host replies
- one nanosecond after sending reply the host crashes
- your method reports all is well, but it isn't is it (see 3)
Do you try to determine if a disk is working on your PC before you use it? I think you attempt to use it knowing that the system will let you know if there is a problem.
But some people still feel like they have a need to check. If you do please use this method.
Code:
Private Function IsMyLittlePieceOfHeavenConnectedToTheInternet() As Boolean
'
'router receives packet
'if TTl = 0 then reply TtlExpired else decrement TTL and forward
'
' MY home network - options.Ttl = 4
' myPC --> WIFI Router --> Wired Router --> ISP Router in my home --> Internet
' TTL 4 3 2 1 0
'
' Other Common Setup A - options.Ttl = 3
' __PC --> Your Router --> ISP Router in home --> Internet
' TTL 3 2 1 0
'
' Other Common Setup B - options.Ttl = 2
' __PC --> ISP Router in home --> Internet
' TTL 2 1 0
'
Dim rv As Boolean = False
Dim ping As New Net.NetworkInformation.Ping
Dim reply As Net.NetworkInformation.PingReply
Dim options As New Net.NetworkInformation.PingOptions
options.Ttl = 4 'adjust this depending on the size of YOUR network
Const PingTMO As Integer = 50
Try
Dim buf(4) As Byte
reply = ping.Send("google.com", PingTMO, buf, options)
If reply.Status = Net.NetworkInformation.IPStatus.TtlExpired Then
'reply.Address should NOT be an address on YOUR network
'if it is then options.Ttl should be increased by 1
'until it is not
Debug.WriteLine(reply.Address)
rv = True
End If
Catch ex As Exception
'a lot of reasons to be here, but they all mean
'your internet connection is down
End Try
Return rv
End Function
The Internet starts at your ISP, so that is really all you need to check. It also means that your need to check on the past doesn't affect the rest of us.
The method works by using the TimeToLive(TTL) field of the ICMP EchoRequest packet.
When a router receives a packet it checks the TTL field.
If the TTL is zero it sends a response of TtlExpired.
If the TTL is not zero it decrements it and forwards the request.
If you want to reply to this and tell me how wrong I am, do this before you do so.
- Open a command prompt (DOS) window.
- Ping this forum by typing ping www.vbforums.com
- When you get a good response you can reply to me.
If you want to reply to this and tell me how smart I am, do so.(I crack me up )
I wouldn't be surprised if one day google turned off ICMP replies to outside networks and it caused major problems, maybe worse that Y2K.
Thanks.
Last edited by dbasnett; Mar 26th, 2016 at 11:44 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|