Skip to content

Instantly share code, notes, and snippets.

@byt3bl33d3r
Last active August 3, 2022 05:16
Show Gist options
  • Save byt3bl33d3r/0e0e07c45007af86fafe4ecc3718b113 to your computer and use it in GitHub Desktop.
Save byt3bl33d3r/0e0e07c45007af86fafe4ecc3718b113 to your computer and use it in GitHub Desktop.
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