Skip to content

Instantly share code, notes, and snippets.

@drunderscore
Last active December 17, 2018 20:06
Show Gist options
  • Save drunderscore/3151df74605780c34e95ee78dbddef2d to your computer and use it in GitHub Desktop.
Save drunderscore/3151df74605780c34e95ee78dbddef2d to your computer and use it in GitHub Desktop.
// James Puleo (2018)
/*
Node script to give Discord proxy servers the wrong image
Their proxy server's aren't very identifiable based by their UA,
but one thing that many of the servers had in common was that the
response was from Firefox 38.0, which is highly deprecated. It seemed
to never be from anything else. Not full-proof, but it works very successfully.
*/
var express = require("express");
var useragent = require("useragent");
var app = express();
app.all("*", (req, res, next) => {
console.log("Got request!");
console.log("Address: " + req.connection.remoteAddress);
console.log("Port: " + req.connection.remotePort);
console.log("user-agent: " + req.headers["user-agent"]);
var agent = useragent.parse(req.headers["user-agent"]);
console.log(
`Using ${agent.family}, version ${agent.major}/${agent.minor}/${
agent.patch
}`
);
console.log("isDiscordProxy: " + isDiscordProxy(agent));
next();
});
app.get("/", (req, res) => {
var headersRet = "";
res.send(
"Your user agent is: <span style='font-family: Consolas'>" +
req.headers["user-agent"] +
"</span>"
);
});
function isDiscordProxy(agent) {
return (
(agent.family.toUpperCase() === "FIREFOX" && parseInt(agent.major) <= 38) ||
agent.family === "Discordbot"
);
}
app.get("/a5jk3g.jpg", (req, res) => {
var agent = useragent.parse(req.headers["user-agent"]);
if (isDiscordProxy(agent)) {
// This is a discord image proxy.
res.sendFile("proxy_image.jpg", { root: "." });
} else {
// Probably not discord image proxy server.
res.redirect("https://www.youtube.com/watch?v=6n3pFFPSlW4");
}
});
app.listen(3000, "0.0.0.0");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment