# Creating an ASN based IP bot traffic filterlist: Easily or for free

**URL:** <https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271>\
**Category:** Database Downloads\
**Tags:** database, ip-privacy-detection, asn, bot\
**Created:** [August 16, 2023, 1:57am UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271 "2023-08-16T01:57:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdullah](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.ipinfo.io/abdullah/32/4973_2.png) [@Abdullah](https://community.ipinfo.io/u/Abdullah)\
**Post date:** [August 16, 2023, 1:57am UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271/1 "2023-08-16T01:57:06Z")

</div>

# ASN-based bot/hosting IP detection is considered one of the most effective ways to prevent bot traffic from your site.

 ![ASN based bot detection](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/1/15d99aa08225ec8f730f7b8f43e6016e878420ed.png)

## ASN based bot detection

ASN (Autonomous System Number) is a unique identifier for an organization that owns a range of IP addresses. ISPs, large organizations, hosting/data centers, educational institutes, government organizations, etc., tend to be AS organizations.

Your average bot is likely hosted on a server of a hosting provider or data center. These bots use the IP addresses of the hosting provider’s ASN. By identifying the IP address of a bot and, progressively, its ASN, you can ban or block access to all non-human traffic from that hosting provider to your website or services hosted.

Average users tend to use ISP IP addresses, which are categorized under the ISP AS organization, while bots, crawlers, and scrapers use hosting IP addresses, which are categorized under the Hosting AS organization.

We have tons of resources about ASNs and the internet ecosystem in general. I highly recommend you to check out our [blogs](https://ipinfo.io/blog/) or our community posts (_you are here_) to learn more about it.

Now, What do I mean by _easily_ or _free_? Well…

## Identifying bots and hosting IP address _easily_

If you want an easy solution, you can choose our premium API or database services. We already provide bot detection and data center/hosting IP detection. The detection of AS types and anonymous IPs is backed by sophisticated data and behavior-based models.

### [Premium API](https://ipinfo.io/pricing) services

 ![IP Lookup to get asn and anonymous IP value](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/8/8d8376b0001c957870a5ee5539cb16fad5ccb0d6.png)

- **ASN information** (AS Type: Hosting, ISP, Business, Education) | Basic API Tier
- **Anonymous IP detection** (Hosting IP address) | Standard API Tier

🔗 Documentation: [https://ipinfo.io/developers/responses#standard-plan](https://ipinfo.io/developers/responses#standard-plan)

### [Premium database services](https://ipinfo.io/products/ip-database-download)

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/0/05e0eaee155e8990c399f9b5c2cb515baf070615.png)

- [ASN database](https://ipinfo.io/products/asn-database)
- [IP to Privacy Detection](https://ipinfo.io/products/anonymous-ip-database)

🔗 Documentation: [Documentation for IP Database Types - IPinfo.io](https://ipinfo.io/developers/database-types)

## Or, Identifying bots and hosting IP address _for free_

Use a combination of your logs, our [free API](https://ipinfo.io/signup), and [free IP to Country ASN database](https://ipinfo.io/products/free-ip-database). For this approach, you have to build your own DIY bot detection service using the free [IP to ASN database](https://ipinfo.io/developers/ip-to-asn-database). Even though you may not have full coverage of anonymous IPs, and you might block a few genuine traffic IPs here and there, this process is an effective method of blocking data center/bot/hosting IP addresses.

To get started, download the free [IP to ASN](https://ipinfo.io/developers/ip-to-asn-database) or [IP to Country ASN database](https://ipinfo.io/developers/ip-to-country-asn-database). Then, identify certain known ASNs that provide hosting services. You can do that by:

- Looking up suspicious IP addresses from your log and getting their ASN information through our API.
- Identifying popular data centers.
- Doing log enrichment with geolocation + asn information through API / Website / [CLI](https://github.com/ipinfo/cli).

Once you have the ASNs, you can get the list of IP ranges of those ASNs. Then feel free to just add them in your firewall config file.

Here is how I am doing it in our [IP to Country ASN free database available on Snowflake](https://app.snowflake.com/marketplace/listing/GZSTZSHKQ4QY/):

I am choosing the following ASNs, which belong to [Hetzner](https://ipinfo.io/AS24940):

- [AS24940](https://ipinfo.io/AS24940)
- [AS213230](https://ipinfo.io/AS213230)
- [AS212317](https://ipinfo.io/AS212317)

On Snowflake, I use the `country_asn` table and the `range_to_cidr` UDF.

```sql
SELECT
  flat_data.value as HETZNER_IP_RANGES
  FROM (
    SELECT public.range_to_cidr(start_ip, end_ip) as ip_range
        FROM public.country_asn
        WHERE ASN='AS24940'
        OR ASN='AS213230'
        OR ASN='AS212317'
    ) hetzner_ips,
TABLE(FLATTEN(hetzner_ips.ip_range)) flat_data

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/a/a07963a75355e6a5cda99698a7d287b303eb1add.png)

This query returns a list of 3,673 IP ranges. You can check out the [documentation of our Snowflake listings](https://ipinfo.io/developers/snowflake_integration) or community posts on Snowflake to learn about the query. By following this method, you can add more ASNs to the query to get a bigger IP range list. You should keep an eye on your log to identify ASNs of malicious IP ranges. Additionally, you should whitelist some of the ASN IP ranges if you want search engine crawlers to access your site or permit VPN usage.

If you have any questions, feel free to ask here in the community or drop a comment.

* * *

### Related:

- [Preventing bot activity with IPinfo's IP to Privacy Data](https://community.ipinfo.io/t/preventing-bot-activity-with-ipinfos-ip-to-privacy-data/1811)
- [Using IPinfo's IP to Country ASN database in Kaspersky Suricata Rules](https://community.ipinfo.io/t/using-ipinfos-ip-to-country-asn-database-in-kaspersky-suricata-rules/1433)
- [Getting IP data from anonymous IP addresses](https://community.ipinfo.io/t/getting-ip-data-from-anonymous-ip-addresses/1743)

### IPinfo services referenced:

**API**

- [IP to Privacy Detection API](https://ipinfo.io/products/proxy-vpn-detection-api)
- IP to ASN API

**Database**

- [IP to Privacy Detection Database](https://ipinfo.io/products/anonymous-ip-database)
- [IP to ASN Database](https://ipinfo.io/products/asn-database)

**Free / Open access services**

[Signup for a free account today](https://ipinfo.io/signup), and get access to the following services:

- [IP to Geolocation API](https://ipinfo.io/products/ip-geolocation-api)
- [IP to Country ASN database](https://ipinfo.io/products/asn-database)
- [IP to ASN free database](https://ipinfo.io/developers/ip-to-country-asn-database)

---

<div class="post-metadata">

**Author:** ![HQJaTu](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@HQJaTu](https://community.ipinfo.io/u/HQJaTu)\
**Post date:** [August 16, 2023, 2:32pm UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271/2 "2023-08-16T14:32:46Z")

</div>

ASN-based classifying/filtering is exactly what I’m doing on email. Most people wouldn’t bother as cloud-based email is so common. On my own Linux, I’ve tried many things with varying success.

My [project in GitHub](https://github.com/HQJaTu/spammer-block). And [blog-post](https://blog.hqcodeshop.fi/archives/476-Practical-Internet-Bad-Neighborhoods-with-Postfix-SMTPd.html) describing the idea.

I do automate sending SpamCop-reports. As my Postfix is configured to honor their RBL, soon after reporting the culprit’s feed will stop.

---

<div class="post-metadata">

**Author:** ![Abdullah](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.ipinfo.io/abdullah/32/4973_2.png) [@Abdullah](https://community.ipinfo.io/u/Abdullah)\
**Post date:** [August 17, 2023, 2:09am UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271/3 "2023-08-17T02:09:43Z")

</div>

### That is really fantastic stuff!!

I am really happy to see this. I am only exploring the code, but I am trying to figure out a better process to:

> Limit: A non-paid API of ipinfo.ip will serve 5 ASN-queries / day / IP-address.

Do you think it would be possible to use the [open access IP to ASN database](https://ipinfo.io/developers/ip-to-asn-database) here? Users with Paid API tokens can keep using the API service as is, but I think we can certainly do better than 5 requests for our free-tier users.

I have not looked into the code too closely, but I did write an entire proof of concept. Please kindly review the Jupyter Notebook:

🔗 [Suggestion for HQJaTu' spammer-block featuring IPinfo's free tier API and database · GitHub](https://gist.github.com/abdullahdevrel/a39a080e0568b214eac143e2515e68a1)

Essentially using a combination of the API and IP to ASN db, you can get all IP address ranges owned by the ASN. Let me know what you think, please.

---

<div class="post-metadata">

**Author:** ![HQJaTu](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@HQJaTu](https://community.ipinfo.io/u/HQJaTu)\
**Post date:** [August 24, 2023, 4:04pm UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271/4 "2023-08-24T16:04:04Z")

</div>

Thank you for your suggestion. Actually, the reason I’m following this community is to learn of various aspects IPinfo has available. There are so many products and options available, it’s very difficul to keep up.

Going for open access while supporting off-line option for ASN-queries is definitely something I’m going to do for my tooling.

---

<div class="post-metadata">

**Author:** ![Abdullah](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.ipinfo.io/abdullah/32/4973_2.png) [@Abdullah](https://community.ipinfo.io/u/Abdullah)\
**Post date:** [August 24, 2023, 5:28pm UTC](https://community.ipinfo.io/t/creating-an-asn-based-ip-bot-traffic-filterlist-easily-or-for-free/2271/5 "2023-08-24T17:28:05Z")

</div>

That is really awesome, dude. I agree there is so much going on with IP data, it sometimes feels a bit overwhelming. The documentation helps, but IP data solutions are more helpful when presented in a problem-focused and example-driven way. That’s why we have the community. Developers like you come up with challenges and ideas, and we try our absolute best to solve them with IPinfo’s DB and API.

I really appreciate your contribution to OSS cybersecurity solutions. You are always welcome to share your ideas in the community and provide feedback. I’m always happy to help!
