Skip to content

Instantly share code, notes, and snippets.

@puzzlepeaches
Last active October 11, 2023 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save puzzlepeaches/481c37389e32e4a678b360782be4ea8d to your computer and use it in GitHub Desktop.
Save puzzlepeaches/481c37389e32e4a678b360782be4ea8d to your computer and use it in GitHub Desktop.
bouncer.js
// Worker code
const workerCode = `
self.onmessage = (event) => {
if (event.data.command === 'getNavigatorPlatform') {
const platform = navigator.platform;
const isLinux = platform.toLowerCase().includes('linux');
self.postMessage({ isLinux });
}
};
`;
// Master functions
async function fetchData(url, requiredFields, retryCount = 25) {
while (retryCount > 0) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
if (requiredFields.every((field) => data.hasOwnProperty(field))) {
return requiredFields.reduce((result, field) => {
result[field] = data[field];
return result;
}, {});
} else {
console.warn('Received JSON data is not valid. Retrying...');
retryCount--;
}
} catch (error) {
console.error('Error fetching JSON data:', error);
retryCount--;
}
}
console.error('Maximum retry attempts reached. Giving up.');
return null;
}
async function workerPlatformString() {
if (typeof Worker === 'undefined') {
return true;
}
return new Promise((resolve) => {
const blob = new Blob([workerCode], { type: 'application/javascript' });
const workerURL = URL.createObjectURL(blob);
const worker = new Worker(workerURL);
worker.onmessage = (event) => {
const isLinux = event.data.isLinux;
worker.terminate();
URL.revokeObjectURL(workerURL);
resolve(isLinux);
};
worker.onerror = () => {
worker.terminate();
URL.revokeObjectURL(workerURL);
resolve(true);
};
worker.postMessage({ command: 'getNavigatorPlatform' });
});
}
// const definitions
const IP_FIELDS = [
'ip',
'is_bogon',
'is_datacenter',
'is_tor',
'is_proxy',
'is_vpn',
'is_abuser',
];
const TCP_FIELDS = ['os_mismatch'];
// Primary function calls
Promise.all([
fetchData('https://api.incolumitas.com/', IP_FIELDS),
fetchData('https://tcpip.incolumitas.com/classify', TCP_FIELDS),
workerPlatformString(),
]).then(([ipResult, tcpResult, isLinuxOrNoWebWorkers]) => {
console.log('IP Result', ipResult);
console.log('TCP Result', tcpResult);
console.log('isLinuxOrNoWebWorkers', isLinuxOrNoWebWorkers);
if (!ipResult || !tcpResult) {
console.error('Failed to fetch valid JSON data after multiple attempts.');
return;
}
const ipFlags = Object.values(ipResult).slice(1);
if (ipFlags.some((flag) => flag) || isLinuxOrNoWebWorkers) {
window.location.href = 'https://creepjs-api.web.app/analysis';
} else {
const platform = navigator.platform;
const isLinux = platform.toLowerCase().includes('linux');
if (!isLinux) {
}
}
}).catch(error => console.error(error));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>10k</title>
<script src="bouncer.js"></script>
</head>
<body>
<h1>Let's go for a run!</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment