Webcore - Ping Google server to check if my local network is up - Gemini suggestions

First, this code seems to work.

I have been running my code through Gemini recently seeking possible improvements. Gemini says this ...

  1. Problem: WebCoRE’s Make a GET request expects a fully qualified web URL (e.g., https://... or http://...). Passing a raw IP address like 8.8.8.8 without an HTTP scheme or endpoint will fail or throw an HTTP error before returning a 200 status. Furthermore, Google's DNS server on 8.8.8.8 does not serve a web page over HTTP/HTTPS on port 80/443, so an HTTP GET request to 8.8.8.8 will likely timeout or return a connection refused error, never returning 200.
  2. Fix: Use an HTTP endpoint designed for uptime checking. [http://clients3.google.com/generate_204](http://clients3.google.com/generate_204) (returns HTTP 204) or a reliable site like [https://1.1.1.1](https://1.1.1.1) or [https://www.google.com](https://www.google.com) (returns HTTP 200).

Do I need to make some changes?

Gemini is probably correct.

8.8.8.8 is google’s public DNS, not a website, so it wouldn’t surprise me if http requests to that IP address fail.

Do you have specific questions about its explanation?

You can't send a get request to a DNS server. It doesn't serve web pages. You need to send a ping. Or, use one of the suggestions in the Fix section you posted above.

I find that the easiest way to ping any device on your local area network, or on the Internet is to use a user driver written by @thebearmay. Once the driver code is installed, you can create a virtual device called Hubitat Ping. You can create multiple instances of this device to ping vartious devices or web sites. Search for "Hubitat Ping" to find the code.

To determine if you Hubitat is connected to the Internet, simply ping any public DNS server such as Cloudflare (1:1:1:1 or 1:0:0:1) or Google (8:8:8:8 or 8:8:4:4). I also find it useful to ping my router and modem IP addresses.

Thanks for all of the information. The 8.8.8.8 does work and produces a status code of 200. But I read elsewhere that it probably would not work. But it seems to be working properly. https://www.google.com also works. So I was curious if I needed to make changes.

I usually get comments when I speak up - you might want to actually look at what your local network DNS server is - often you get a faster response from your ISP dns. I'm on 2Gig Ziply, so I get a bit faster response from their DNS servers.

c:\wamp64\www>ping 192.152.0.1

Pinging 192.152.0.1 with 32 bytes of data:
Reply from 192.152.0.1: bytes=32 time=5ms TTL=56
Reply from 192.152.0.1: bytes=32 time=4ms TTL=56
Reply from 192.152.0.1: bytes=32 time=4ms TTL=56

Ping statistics for 192.152.0.1:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 4ms, Maximum = 5ms, Average = 4ms

c:\wamp64\www>ping 8.8.8.8

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=8ms TTL=114
Reply from 8.8.8.8: bytes=32 time=7ms TTL=114
Reply from 8.8.8.8: bytes=32 time=8ms TTL=114
Reply from 8.8.8.8: bytes=32 time=8ms TTL=114

Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 7ms, Maximum = 8ms, Average = 7ms

We had our upstream provider give us a warning that pinging google.com could be problematic and to use more localized hardware/IP's so that partial internet outages didn't give a false positive or affect us (I was working for a school district as the network manager at the time):
No, Google does not mind if you ping their public DNS servers (8.8.8.8 or 8.8.4.4). Millions of people and network tools ping them daily to check internet speed or connection health. However, ICMP pings have low priority, so Google may drop or slow down ping replies if too many are sent.

This information is very helpful. My results:

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=11ms TTL=119
Reply from 8.8.8.8: bytes=32 time=11ms TTL=119
Reply from 8.8.8.8: bytes=32 time=10ms TTL=119
Reply from 8.8.8.8: bytes=32 time=10ms TTL=119

Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 10ms, Maximum = 11ms, Average = 10ms

Pinging 1.1.1.1 with 32 bytes of data:
Reply from 1.1.1.1: bytes=32 time=10ms TTL=59
Reply from 1.1.1.1: bytes=32 time=10ms TTL=59
Reply from 1.1.1.1: bytes=32 time=10ms TTL=59
Reply from 1.1.1.1: bytes=32 time=10ms TTL=59

Ping statistics for 1.1.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 10ms, Maximum = 10ms, Average = 10ms

Those speeds are not important for me though as I am just ensuring that I am online.

If you can ping google’s DNS at 8.8.8.8 with webcore that is probably a better strategy than sending an http get. ICMP ping uses a different protocol and port than http.

Does it matter as long as I get a good httpstatuscode?

Yes, because ping is he correct way to query 8.8.8.8.

I guess as long as Google has things setup in a way such that 8.8.8.8 does respond to http requests, it could work for your intended purpose.

Here’s the response I see when I send a GET to 8.8.8.8.

<!DOCTYPE html>

<html lang="en"> <head> <title>Google Public DNS</title>  <meta charset="UTF-8"> <link href="/static/93dd5954/favicon.png" rel="shortcut icon" type="image/png"> <link href="/static/e6eca759/matter.min.css" rel="stylesheet"> <link href="/static/b8536c37/shared.css" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1">  <link href="/static/d05cd6ba/root.css" rel="stylesheet"> </head> <body> <span class="filler top"></span>   <div class="logo" title="Google Public DNS"> <div class="logo-text"><span>Public DNS</span></div> </div>  <form action="/query" method="GET">  <div class="row"> <label class="matter-textfield-outlined"> <input name="name" placeholder="&nbsp;" type="text"> <span>DNS Name</span> <p class="help"> Enter a domain (like example.com) or IP address (like 8.8.8.8 or 2001:4860:4860::8844) here. </p> </label> <button class="matter-button-contained matter-primary" type="submit">Resolve</button> </div> </form>  <span class="filler bottom"></span> <footer class="row"> <a href="https://developers.google.com/speed/public-dns">Help</a> <a href="/cache">Cache Flush</a> <span class="filler"></span> <a href="https://developers.google.com/speed/public-dns/docs/using"> Get Started with Google Public DNS </a> </footer>   <script nonce="VCX_f-0-ZwN7QnO5ZOfArg">document.forms[0].name.focus();</script> </body> </html>


I get an http status of 200 for a GET for either of 8.8.8.8 or https://www.google.com.

So, either should work for me to confirm that I am online.

I suppose so.

Personally I’d stick with the one that’s explicitly meant to receive an http request.

My thoughts exactly. If you're going to something, do it right. This is being used to test for connectivity. Use the right methods for their intended purposes. Ping to IP addresses that accept ping. http requests to URLs that accept those requests.

Agreed. Since a domain name server, strictly speaking, doesn’t reply to an http request, Google must have something else answering those http calls that go to 8.8.8.8.

For the OP’s purposes, I’d consider that to be a happy accident. I suppose it’s unlikely Google will ever shut down that web server at 8.8.8.8, but Google does strange things sometimes.

In contrast, unless Google disappears completely in the future, google.com will always respond to http GETs since that’s literally what it’s designed to do.

Good learning experience for me. I will use the google.com. Thanks everyone!

just commenting, not furthering this discussion - a bit of clarification to my past comment - using a hostname such as google.com requires the DNS to actually be there for the lookup! this adds overhead/delay time. As a previous poster mentioned, DNS is a different protocol then a ping. so point of clarity an HTTP get is not really the same as an icmp echo. I'd be sure I was pinging an IP addr not a hostname, and use the right tool - if I'm checking a website is there an http get to it's ip is a clear task to do so, where checking an IP is there is an icmp call. The web could be down but the ip there, the dns could fail to respond (ddos?) if overwhelming by lookups etc. etc.

So, if all you are doing is checking to see if you have internet access, using webcore, what method would you use?

Ping is the easiest and what you want to test for Internet access. Even Ubiquiti uses ping within their UniFi routers to test for Internet connectivity.

This is from the UniFi Network dashboard on a Dream Machine Pro:

image

Those times are from ping tests to those services.

An http request to a URL, as mentioned above by @jshimota, requires DNS. If whatever you are using for DNS is down, that request will fail regardless if you have actual Internet access.

Trust me on this, use ping.

If you want to use the ping device this piston should let you use it to detect 8.8.8.8