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?
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.
The connection_status() function returns the current connection status. Possible values that can be returned are: 0 - CONNECTION_NORMAL - connection is running normally.
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.
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.
There are two ways to do this that I know of:
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.
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>
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With