Skip to content

Instantly share code, notes, and snippets.

@Oniicode
Created November 18, 2021 21:07
Show Gist options
  • Select an option

  • Save Oniicode/7320fb778c5a67adcf0966a5ef829dbd to your computer and use it in GitHub Desktop.

Select an option

Save Oniicode/7320fb778c5a67adcf0966a5ef829dbd to your computer and use it in GitHub Desktop.
Quick and dirty script to check if a web server host is connected to the internet using VPN
<?php
$ip = file_get_contents("https://api.ipify.org/");
if(!isset($_GET["raw"]))
echo "WAN IP from backend: " . $ip;
else {
echo $ip;
return;
}
?>
<script>
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
const ipclient = httpGet("https://api.ipify.org/");
const ipserver = httpGet("?raw");
const seemssafe = ipclient != ipserver;
alert("Check: " + seemssafe + "\nIP from browser: " + ipclient + "\nIP from server: " + ipserver);
window.history.back();
</script>
<a href="/">Back Home</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment