How do I block a host by ASN? Example - AS16276

You can use https://www.enjen.net/asn-blocklist/

An example i.e. colocrossing: https://www.enjen.net/asn-blocklist/index.php?asn=AS36352&type=htaccess

If you need to download it to a server and don't want html then add &api=1 to the end of the link.


Check out mod_asn:

mod_asn is an Apache module that uses BGP routing data to look up the autonomous system (AS) and the network prefix (subnet) which contains a given (clients) IP address.

mod_asn is usable as standalone module, and the lookup result can be used by scripts or other Apache modules. For instance, a download redirector could base its decisions on the lookup result provided by mod_asn.

I don't have any direct experience with this, but it sounds promising.

Someone with direct experience with this module should feel free to edit this answer to add relevant specific details.

Additionally, you can talk with your network administrator to have these ASNs blocked or ignored at the router, then you don't have to make this an application configuration problem. A (major?) drawback to the mod_asn approach is that it doesn't stop naughty IP addresses from trying to attack other services on your host or network, it will only drop HTTP/HTTPS requests to the configured apache servers.