Skip to content

Instantly share code, notes, and snippets.

@ankurparihar
Last active September 28, 2024 20:27
Show Gist options
  • Save ankurparihar/b43e5c5d51ea09a515e3cd3e80ed0547 to your computer and use it in GitHub Desktop.
Save ankurparihar/b43e5c5d51ea09a515e3cd3e80ed0547 to your computer and use it in GitHub Desktop.
counttoamillion-challenge-script
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
process.exit(1);
});
let begin = 1;
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Received: '" + message.utf8Data + "'");
try {
const {value} = JSON.parse(message.utf8Data);
begin = value+1;
} catch (error) {
console.error(`parsing error`, message.utf8Data);
}
sendNext();
}
});
function sendNext(){
connection.send(JSON.stringify({
type: "update-count",
"value": begin++
}))
}
});
client.connect('wss://api.counttoamillion.com/score', 'echo-protocol', "https://counttoamillion.com", {
cookie: "_ga=GA1.1.305294779.1727544835; __cf_bm=9.h7HbdFXLfSO3jssYCRrIBZxHlZcYRo4GY_.Bts55s-1727544835-1.0.1.1-.7vgPRlXmOKT7G.njNb4VdmivRiUp_ZfSQywGawOJrKdnYf9e9USzi8DIyEmMekOrDRWWBkEJrKoUdtg3aq3EQ; session=2e69c256-cb3e-450f-b028-74044c398758; _ga_CGDJG53NZW=GS1.1.1727544835.1.1.1727544995.0.0.0",
"sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
"sec-websocket-version": 13,
"sec-websocket-key": "rAFyF97qnokQvlIpmEt43w==",
accept: "gzip, deflate, br, zstd",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
connection: "Upgrade",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
});
{
"name": "counttoamillion",
"version": "1.0.0",
"description": "",
"main": "brute.js",
"scripts": {
"start": "node brute.js"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment