Skip to content

Instantly share code, notes, and snippets.

@aranajhonny
Created February 5, 2020 17:36
Show Gist options
  • Save aranajhonny/dadf28964f990a810ebf561ceefa40df to your computer and use it in GitHub Desktop.
Save aranajhonny/dadf28964f990a810ebf561ceefa40df to your computer and use it in GitHub Desktop.
detect if are using vpn
function detectVPN() {
var browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
return fetch(`https://ipapi.co/json`)
.then(function(response) { return response.json() })
.then(function (data) {
var ipTimezone = data.timezone
console.log(`browser timezone: ${browserTimezone}`, `ip timezone: ${ipTimezone}`)
return {
browser: browserTimezone,
ip: ipTimezone,
usingVPN: ipTimezone != browserTimezone
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment