Last active
December 9, 2020 13:07
-
-
Save Santinell/f6e704551ce8092cb584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
function getIP(data) { | |
var a = data.slice(0, 1).readUInt8(); | |
var b = data.slice(1, 2).readUInt8(); | |
var c = data.slice(2, 3).readUInt8(); | |
var d = data.slice(3, 4).readUInt8(); | |
return (a + "." + b + "." + c + "." + d); | |
} | |
function getPort(data) { | |
return data.slice(4, 6).readUInt16BE(); | |
} | |
function parse(data) { | |
var res = []; | |
data = data.slice(6); | |
while (data.length) { | |
ip = getIP(data); | |
port = getPort(data); | |
res.push([ip, port]); | |
data = data.slice(6); | |
} | |
return res; | |
} | |
var start = new Buffer([0x31]); | |
var location = new Buffer([0xFF]); | |
var ipPort = new Buffer("0.0.0.0:0"); | |
var filters = new Buffer([0]); | |
var message = Buffer.concat([start, location, ipPort, filters]); | |
var socket = dgram.createSocket("udp4"); | |
socket.bind(1234, function() { | |
socket.send(message, 0, message.length, 27011, "hl2master.steampowered.com"); | |
socket.on('message', function(msg, rinfo) { | |
console.log(parse(msg)); | |
socket.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment