Workers get hostname


#1

Hi There,

I want to find out in the if I get traffic from bot traffic for that I want to check the host name,

Is there any way to check the host name inside the workers? or inside the html client (I don’t want to use server side)

I know there is option in the to filter by host firewall buy I want to have some logic inside the worker/client without using server side code…

Best,
Dan


#2

This is an example from here:

addEventListener('fetch', event => {
  event.respondWith(fetchAndApply(event.request))
})

async function fetchAndApply(request) {  
  if (request.headers.get('user-agent').includes('annoying_robot')) {
    return new Response('Sorry, this page is not available.',
        { status: 403, statusText: 'Forbidden' })
  }

  return fetch(request)
}

#3

Thanks for the example

However I looking for the ISP of the visitor

So I will be able the check if the ISP if its real service provider or hosting company


#4

Then you could limit by Autonomous System Number:
request.cf.asn


#5

Great! any idea how can I get the ASN Name ? (and not the number)


#6

One way:
https://ipinfo.io/AS15169


#7

Great found it!