Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to detect if a user is on a wifi connection with php or javascript?

Tags:

javascript

php

Cant seem to find any info on this, but was wondering if there is any way to detect if a user is on a wifi connection, specifically public wifi, using javascript, or php?

like image 973
mcbeav Avatar asked Dec 16 '10 09:12

mcbeav


People also ask

How do you see if someone is connected to the WiFi?

Use a Wi-Fi detective app You can search the app store for options, but one reliable app is called WiFi Guard, available for both iOS and Android. This app gives you a list of all connected devices, which you can scan to see if there are any devices you don't recognize.

How can I check my Internet connection in PHP?

The connection_status() function returns the current connection status. Possible values that can be returned are: 0 - CONNECTION_NORMAL - connection is running normally.

How do I know if JavaScript is connected to Internet?

JavaScript has a function called navigator. This browser property can be used to determine if you are connected to the internet. It returns true or false depending on the status of the client's network and says whether the browser is online or offline easily.

Can public WiFi be monitored?

If you don't take precautions, information your devices send over a public WiFi network goes out in clear text — and anyone else on the network could easily take a look at what you're doing with just a few simple software tools. Someone spying could easily pick up your passwords or other private information.


3 Answers

There are two ways to do this that I know of:

  1. Check the IP against a database. This option gives you much more than carrier information, by the way. It can also give you the location and name of the ISP, the domain that maps to this IP, lat/long, zip code, time zone, etc., etc. Look at http://www.quova.com/ for a RESTful API that allows this.

  2. Programmatically: This only works on Android version 2.2+. It is a simple check for navigator.connection. Hope this helps. Here is a test page:

<html>
    <head>
        <script type="text/javascript">
            function checkWIFI() {
                var output = document.getElementById('connectionCheck');
                var html = "Checking...<br/>Connection: ";
                if (navigator.connection) {
                    var type = navigator.connection.type;
                    switch (type) {
                        case navigator.connection.UNKNOWN:
                            html += "Unknown";
                            break;
                        case navigator.connection.ETHERNET:
                            html += "Ethernet";
                            break;
                        case navigator.connection.WIFI:
                            html += "Wifi";
                            break;
                        case navigator.connection.CELL_2G:
                            html += "Cell 2G";
                            break;
                        case navigator.connection.CELL_3G:
                            html += "Cell 3G";
                            break;
                        default:
                            html += "Missing";
                    }
                } else {
                    html += "Connection type not supported.";
                }
                output.innerHTML = html;
            }
        </script>
    </head>
    <body onload="checkWIFI();">
        <div id="connectionCheck">
        </div>
    </body>
</html>
like image 60
Sky Kelsey Avatar answered Sep 23 '22 12:09

Sky Kelsey


JSFiddle Example

if (navigator.onLine) { //Works in most browsers. Not all.
  document.getElementById("online").innerText = "Online";
} else {
  document.getElementById("online").innerText = "Offline";
}
<html>
  <div id="online"></div>
</html>
like image 20
Visal Avatar answered Sep 21 '22 12:09

Visal


No, there isn't, there is nothing in the IPv4 nor the HTTP transport that even hints at what kind of connection is used, except for the underlying protocol itself, which is usually IPv4 and HTTP.

No, IPv6 doesn't include this information either.

like image 38
Arafangion Avatar answered Sep 23 '22 12:09

Arafangion