Skip to content

Instantly share code, notes, and snippets.

View stenito's full-sized avatar

stenito stenito

View GitHub Profile
@stenito
stenito / loadscreen.css
Last active January 10, 2022 13:24
Add an overlay to a HTML page until all fonts are loaded.
/* Add to head style tag */
[data-loadscreen] {
opacity: 1;
z-index: 10000;
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
@stenito
stenito / publicip.js
Last active February 15, 2021 14:44
Get public IP address (wan IP address) in node
const https = require('https');
const options = {
hostname: 'httpbin.org',
port: 443,
path: '/ip',
method: 'GET'
}
const req = https.request(options, res => {
res.on('data', d => {
@stenito
stenito / publicip.js
Last active February 15, 2021 12:39
Get public IP address (wan IP address) using XMLHttpRequest JavaScript function
function getPublicIP() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://httpbin.org/ip", true); // false for synchronous request
xhr.onload = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let yourWanIP = JSON.parse(xhr.responseText).origin;
// do what you want to do with the IP address
// ... eg. log it to the console
console.log(yourWanIP);
@stenito
stenito / publicip.js
Last active February 15, 2021 12:32
Get public IP address (or wan IP address) using fetch JavaScript function (not supported in IE)
function getPublicIP() {
fetch('http://httpbin.org/ip')
.then(response => response.json())
.then(data => {
// do what you want to do with the IP address
// ... eg. log it to the console
console.log(data.origin);
});
}
@stenito
stenito / publicip.php
Last active May 21, 2024 13:01
Get public IP address (or wan IP address) with php function
<?php
function getPublicIP() {
// create & initialize a curl session
$curl = curl_init();
// set our url with curl_setopt()
curl_setopt($curl, CURLOPT_URL, "http://httpbin.org/ip");
// return the transfer as a string, also with setopt()