Last active
August 3, 2022 05:16
-
-
Save byt3bl33d3r/0e0e07c45007af86fafe4ecc3718b113 to your computer and use it in GitHub Desktop.
HonoJS Redirector - https://byt3bl33d3r.substack.com/publish/post/66929654
This file contains 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
import { Hono } from "hono"; | |
const app = new Hono() | |
app.get('/', async (c) => { | |
const bad_user_agent_array = ['curl', 'httpie'] | |
const user_agent = c.req.header('User-Agent') | |
const ip = c.req.header("CF-Connecting-IP") | |
console.log(user_agent) | |
//Object.keys(c.req.cf) | |
// .forEach( key => console.log(`${key}: ${c.req.cf[key]}`)) | |
const user_agent_test = bad_user_agent_array.some( x => { | |
return user_agent.toLowerCase().startsWith(x.toLowerCase()) | |
}) | |
const asn_org_test = c.req.cf.asOrganization.starsWith("Microsoft") | |
const detected = user_agent_test || asn_org_test | |
console.log(detected) | |
switch(detected){ | |
case true: | |
return c.body('nope', 404) | |
case false: | |
return c.body('yes', 200) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment