Internet Check

Post Reply
User avatar
rbytes
Posts: 1963
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Internet Check

Post by rbytes » Wed Nov 21, 2018 6:56 pm

;)
Last edited by rbytes on Thu Jun 13, 2019 5:41 am, edited 1 time in total.
Zzzzz

User avatar
Dutchman
Posts: 915
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Internet Check

Post by Dutchman » Thu Nov 22, 2018 9:35 am

Thank you Richard.
This website "What is the Best IP address to Ping to Test my Internet Connection?" provides useful additional information: https://etherealmind.com/what-is-the-be ... onnection/
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

User avatar
rbytes
Posts: 1963
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Internet Check

Post by rbytes » Thu Nov 22, 2018 12:20 pm

Thanks for this valuable information. :idea:
Zzzzz

User avatar
Dutchman
Posts: 915
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Internet Check

Post by Dutchman » Fri Nov 23, 2018 6:37 pm

I have adapted the function for use in iConvert.
The necessary constants and error messages are now within the function. Moreover, if PING with code 80 fails, the test is again performed with code 8080, as George suggested.
As default 'refname$' I have chosen "dns.google.com".
It was mentioned in https://etherealmind.com/what-is-the-be ... onnection/
and explained further in https://developers.google.com/speed/pub ... over-https
It is the default name, but can be changed to 'url$' with the command: 'NetStatus.refname$=url$'

The message about the status is now also locally generated and returned as a result. Therefore, now the level range could also be changed to 0-2, because it does not have to fit in the command 'ON x GOTO'.
So level=0 means 'no internet'.
The result can now be printed in a single line of code. The level can be requested as a local variable.

Code: Select all

 
/*
NetStatus$() by Dutchman
adapted from "Internet Check" by rbytes, November 2018

To test this program:
a. Run it with name$ set to active websites. Return value = 2
b. Run it with name$ deliberately misspelled. Return value = 1
c. Run it with your device in Airplane mode. Return value = 0
*/

PRINT NetStatus$("www.apple.com")&" Statuslevel="&NetStatus$.level
END

'r'
DEF NetStatus$(name$)
' by Rbytes, adapted by Dutchman
' Return.level ranges from 0-2
' Usage:
' See https://bit.ly/2Aelgu7 and https://bit.ly/2PHqYzb
' On DNS: https://developers.google.com/speed/public-dns/docs/dns-over-https
DNSurl$="dns.google.com" 'See https://bit.ly/2PHqYzb
' refname$ can be preset to 'url$' with 'NetStatus.refname$=url$'
IF refname$="" THEN refname$=DNSurl$
'
ob=OPTION_BASE()
OPTION BASE 1
' Messages can be overwritten in NetStatus.Msg$()
IF Msg$(1)="" THEN GOSUB Init
'--- Ping with code=80 and code=8080
code=80
DO
  Level=0
  GOSUB Call
   IF code=80 AND Level<3 THEN
    FirstLevel=Level
    code=8080
  ENDIF
UNTIL Level=2 OR code=8080
Level=MAX(Level,FirstLevel)
Status$=Msg$(level+1)
OPTION BASE ob
RETURN Status$ ' reurn from function
'
'----- local subroutine
Call:
Level=PING(TRIM$(name$),code)
IF Level THEN 
  Level+=1
  RETURN
ELSE
  Level=PING(refname$,code)
ENDIF
RETURN ' from subroutine
'---- local subroutine
Init:
DIM Msg$(3)
FOR i=1 TO 3
  READ Msg$(i)
NEXT i
RETURN ' from local subroutine
DATA "Internet connection failed."
DATA "Website is not responding."
DATA "Website is responding."
END DEF
''
I also created a second version that retains the message as a local variable and returns the level.

Code: Select all

 /*
NetStatus() by Dutchman
adapted from "Internet Check" by rbytes, November 2018

To test this program:
a. Run it with name$ set to active websites. Return value = 2
b. Run it with name$ deliberately misspelled. Return value = 1
c. Run it with your device in Airplane mode. Return value = 0
*/

result=NetStatus("www.apple.com")
PRINT NetStatus.Status$& " Statuslevel="&result&". "
END

'r'
DEF NetStatus(name$)
' by Rbytes, adapted by Dutchman
' Return.level ranges from 0-2
' Usage:
' See https://bit.ly/2Aelgu7 and https://bit.ly/2PHqYzb
' On DNS: https://developers.google.com/speed/public-dns/docs/dns-over-https
DNSurl$="dns.google.com" 'See https://bit.ly/2PHqYzb
' refname$ can be preset to 'url$' with 'NetStatus.refname$=url$'
IF refname$="" THEN refname$=DNSurl$
'
ob=OPTION_BASE()
OPTION BASE 1
' Messages can be overwritten in NetStatus.Msg$()
IF Msg$(1)="" THEN GOSUB Init
'--- Ping with code=80 and code=8080
code=80
DO
  Level=0
  GOSUB Call
   IF code=80 AND Level<3 THEN
    FirstLevel=Level
    code=8080
  ENDIF
UNTIL Level=2 OR code=8080
Level=MAX(Level,FirstLevel)
Status$=Msg$(level+1)
OPTION BASE ob
RETURN Level ' reurn from function
'
'----- local subroutine
Call:
Level=PING(TRIM$(name$),code)
IF Level THEN 
  Level+=1
  RETURN
ELSE
  Level=PING(refname$,code)
ENDIF
RETURN ' from subroutine
'---- local subroutine
Init:
DIM Msg$(3)
FOR i=1 TO 3
  READ Msg$(i)
NEXT i
RETURN ' from local subroutine
DATA "Internet connection failed."
DATA "Website is not responding."
DATA "Website is responding."
END DEF
''
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Internet Check

Post by GeorgeMcGinn » Sun Dec 02, 2018 9:27 pm

Hi Dutchman,

I need to caution you about using an IP address for checking a specific website. The issue comes with whether or not the person who set up the webserver has set up one IP address for his machine, and uses the Domain Name Server (DNS) to resolve where the request goes.

You see this more with corporate websites then websites that are hosted by a company whose business is to host virtual websites. You see a corporation will have one IP address for all its Internet traffic and it will use the DNS to direct traffic to the proper page. When I had my webserver online, I hosted other people's websites, so to give them each their own IP address, I had apply and pay for a range of IP addresses. Otherwise I would have been stuck with my one IP address and had to use the DNS to resolve which subdirectory on the HTTPD server the request goes to.

That would be the only issue using just the IP address. It is useful, because if you can't get to the website and you know its IP address, then you can actually check to see if the entire machine is down or not. In other words, you could get a fail on the domain name but get a successful code using the IP address.

It may sound confusing but unfortunately that's the way the Internet is set up. There's only an infinite number of IP address is, and now that IoT devices will also have their own IP address, everybody's going to have to switch over to the IPv6 format. IoT are sensors and other devices like homemade home alarm systems that have Internet access to them will need to have an IP address and not a domain name. This means tens of billions of you more IP addresses will be needed in the future.

Wikipedia has a good write up on the IPv4 versus a IPv6, and why we will soon be running out of IP addresses. That's one of the reasons why virtual servers in virtual down domain names were created so that they all can use the same IP address it just gets dissolved by the server.

Link: https://en.m.wikipedia.org/wiki/IPv6


Dutchman wrote:
Thu Nov 22, 2018 9:35 am
Thank you Richard.
This website "What is the Best IP address to Ping to Test my Internet Connection?" provides useful additional information: https://etherealmind.com/what-is-the-be ... onnection/
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

User avatar
Dutchman
Posts: 915
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Internet Check

Post by Dutchman » Mon Dec 10, 2018 9:38 am

GeorgeMcGinn wrote:
Sun Dec 02, 2018 9:27 pm

I need to caution you about using an IP address for checking a specific website. The issue comes with whether or not the person who set up the webserver has set up one IP address for his machine, and uses the Domain Name Server (DNS) to resolve where the request goes.
Thank you, George for the reaction.
I only have some trouble to draw the conclusion. It is really confusing.
Can I use "dns.google.com" to check the network connection or do you recommend a different address?
Which address?
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

User avatar
rbytes
Posts: 1963
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Internet Check

Post by rbytes » Mon Dec 10, 2018 3:36 pm

Therefore, now the level range could also be changed to 0-2, because it does not have to fit in the command 'ON x GOTO'.
I have used variables with values starting at 0 in ON x GOTO statements. It is true that ON x GOTO will treat 0 the same as 1. This is true regardless of the value of OPTION BASE x. But the following code shows a workaround:

Code: Select all

x=0
ON x+1 GOTO 10,20,30
10 BEEP!GOTO 40
20 BEEP!BEEP!GOTO 40
30 BEEP! BEEP!BEEP
40 PAUSE 5
END
It works with x having integer values from 0 to 2.
Zzzzz

User avatar
GeorgeMcGinn
Posts: 495
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Internet Check

Post by GeorgeMcGinn » Sat Jan 12, 2019 8:10 pm

Hi Dutchman,

Sorry for the late response but I had a very bad month for December. I got sick because the nurse of my doctor refused to renew three prescriptions that cause serious with drawl symptoms that almost put me in the hospital. I had that straightened out now after filing an official complaint with my medical offices corporate office against the nurse who wound up violating their own procedures.

Also, two people that I know, one real close, died during the month of December, so I wasn't in any shape to do anything until I got my meds straightened out and then I got over the death of a mentor of mine.

I had to do some research into this and I did not know about the Google DNS. I tried it on several IP address is including the one you use in your program (192.170.61.53) and I got stays 3, which looks like an error message. (See attached image). I also noticed that this feature is in beta, so I'm not sure whether it's working properly or not. I also noticed that it produces a couple of different IP addresses, which means that the DNS might be resolving the initial IP address into others. I don't know why, unless the IP address given to you is shared, which is possible. The DNS server will be based on domain name pointed to the right server. But not knowing what the Google DNS website does, I can't say for sure.

It does provide however, a way that you can use a HTTPD protocol and it looks like it returns a JSON message back (see below).

All I can say is I need to do more research into this before I can give you an answer. It does however, look like it produces more information than just a regular PING.

URL
https://dns.google.com/resolve?name=192 ... :80&type=A

RESULTS
{"Status": 3,"TC": false,"RD": true,"RA": true,"AD": true,"CD": false,"Question":[ {"name": "192.170.61.43:80.","type": 1}],"Authority":[ {"name": ".","type": 6,"TTL": 86398,"data": "a.root-servers.net. nstld.verisign-grs.com. 2019011201 1800 900 604800 86400"}]}

Here is the image that shows what it produces when you type in the URL at the dns.google.com:
IMG_0790.PNG
IMG_0790.PNG (294.65 KiB) Viewed 315 times

Dutchman wrote:
Mon Dec 10, 2018 9:38 am
GeorgeMcGinn wrote:
Sun Dec 02, 2018 9:27 pm

I need to caution you about using an IP address for checking a specific website. The issue comes with whether or not the person who set up the webserver has set up one IP address for his machine, and uses the Domain Name Server (DNS) to resolve where the request goes.
Thank you, George for the reaction.
I only have some trouble to draw the conclusion. It is really confusing.
Can I use "dns.google.com" to check the network connection or do you recommend a different address?
Which address?
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
https://www.georgemcginn.com
https://www.cosmologyandspace.blog

Post Reply