Mail::...in::ASN(3pm)

✨ NAME ✨

Mail::SpamAssassin::Plugin::ASN β€” bestie, this is the SpamAssassin plugin that goes and finds out the Autonomous System Number (ASN) of the IP address that's connecting to you. That's it, that's the whole job, and it does it beautifully. πŸ¦‹

This one lives in the perl manual pages, in the User Contributed Perl Documentation section β€” so you know it's good.


πŸŽ€ SYNOPSIS πŸŽ€

Like, here's the whole vibe in one block, copy-paste ready:

loadplugin Mail::SpamAssassin::Plugin::ASN

# Default / recommended settings
asn_use_geodb 1
asn_use_dns 1
asn_prefer_geodb 1

# Do lookups and add tags / X-Spam-ASN header
asn_lookup asn.routeviews.org _ASN_ _ASNCIDR_
asn_lookup_ipv6 origin6.asn.cymru.com _ASN_ _ASNCIDR_
add_header all ASN _ASN_ _ASNCIDR_

# Rules to test ASN or Organization
# NOTE: Do not use rules that check metadata X-ASN header,
# only check_asn() eval function works correctly.
# Rule argument is full regexp to match.

# ASN Number: GeoIP ASN or DNS
# Matched string includes asn_prefix if defined, and normally
# looks like "AS1234" (DNS) or "AS1234 Google LLC" (GeoIP)
header AS_1234 eval:check_asn('/^AS1234\b/')

# ASN Organisation: GeoIP ASN has, DNS lists might not have
# Note the second parameter which checks MYASN tag (default is ASN)
asn_lookup myview.example.com _MYASN_ _MYASNCIDR_
header AS_GOOGLE eval:check_asn('/\bGoogle\b/i', 'MYASN')

okay but read the NOTE, fr fr β€” do not write rules that peek at the metadata X-ASN header. Only the check_asn() eval function works correctly. The rule argument is a full regexp to match. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

So this plugin uses DNS lookups to the services of an external DNS zone β€” like the one at https://www.routeviews.org/ β€” to actually do the work.

🫢 Please, please make sure your use of this plugin does not overload their infrastructure. In practice that means: do not use this plugin in a high-volume environment, or use a local mirror of the zone instead (see ftp://ftp.routeviews.org/dnszones/). Other similar zones may also be used. Be a considerate queen. 🌸

GeoDB (GeoIP ASN) database lookups are supported since SpamAssassin 4.0, and honestly it's recommended to use them instead of DNS queries β€” unless you need _ASNCIDR_.


🌈 TEMPLATE TAGS 🌈

This plugin lets you create template tags containing the connecting IP's AS number and the route info for that AS number. Iconic behaviour, no notes.

If you use add_header like the example showed earlier, you get a header field that looks like this:

X-Spam-ASN: AS24940 213.239.192.0/18

...where 24940 is the ASN, and 213.239.192.0/18 is the route announced by that ASN that the connecting IP address came from. πŸ’«

If the AS announces multiple networks (more/less specific), they all get added to the _ASNCIDR_ tag, separated by spaces, like:

X-Spam-ASN: AS1680 89.138.0.0/15 89.139.0.0/16

Note that the literal "AS" sitting before the ASN in the _ASN_ tag is configurable through the asn_prefix directive, and you can set it to an empty string if that's your vibe.

😭 Heads up bestie: _ASNCIDR_ is not available with local GeoDB ASN lookups. It's just not.

πŸ’œ USER SETTINGS πŸ’œ

  • clear_asn_lookups β€” Removes all previously declared asn_lookup or asn_lookup_ipv6 entries from the list of queries. Fresh start energy. 🧹
  • asn_prefix 'prefix_string' (default: 'AS') β€” The string you put in the argument gets prepended to each ASN when it's stored as a tag. This prefix is rather redundant, ngl, but its default value 'AS' is kept for backward compatibility with versions of SpamAssassin earlier than 3.4.0. A sensible setting is an empty string. The argument may be (but does not have to be) wrapped in single or double quotes for clarity.

πŸ”₯ RULE DEFINITIONS AND PRIVILEGED SETTINGS πŸ”₯

  • asn_lookup asn-zone.example.com [ _ASNTAG_ _ASNCIDRTAG_ ] β€” Use this to look up the ASN info in the specified zone for the first external IPv4 address, and add the AS number to the first specified tag and the routing info to the second specified tag.

If you specify no tags, the AS number goes into the _ASN_ tag and the routing info goes into the _ASNCIDR_ tag. You must specify either none or both of the tag names. Tag names must start and end with an underscore.

If two or more asn_lookups use the same set of template tags, the results of their lookups get appended to each other in the template tag values in no particular order. Duplicate results are omitted when combining results. In a similar fashion, you can also use the same template tag for both the AS number tag and the routing info tag. slay, versatile. ✨

Examples:

asn_lookup asn.routeviews.org

asn_lookup asn.routeviews.org _ASN_ _ASNCIDR_
asn_lookup myview.example.com _MYASN_ _MYASNCIDR_

asn_lookup asn.routeviews.org _COMBINEDASN_ _COMBINEDASNCIDR_
asn_lookup myview.example.com _COMBINEDASN_ _COMBINEDASNCIDR_

asn_lookup in1tag.example.net _ASNDATA_ _ASNDATA_
  • asn_lookup_ipv6 asn-zone6.example.com [_ASN_ _ASNCIDR_] β€” Use the specified zone for lookups of IPv6 addresses. If a zone supports both IPv4 and IPv6 queries, use both asn_lookup and asn_lookup_ipv6 for the same zone. 🌐

πŸ‘‘ ADMINISTRATOR SETTINGS πŸ‘‘

  • asn_use_geodb ( 0 / 1 ) (default: 1) β€” Use the Mail::SpamAssassin::GeoDB module to look up ASN numbers. You need a suitable supported module like GeoIP2 or GeoIP with an ISP or ASN database installed (for example, add EditionIDs GeoLite2-ASN in GeoIP.conf for the geoipupdate program).

GeoDB can only set the _ASN_ tag β€” it has no data for _ASNCIDR_. If you need both, then set asn_prefer_geodb 0 so DNS rules get tried. πŸ’«

  • asn_prefer_geodb ( 0 / 1 ) (default: 1) β€” If set, DNS lookups (asn_lookup rules) will not be run if GeoDB successfully finds the ASN. Set this to 0 to get _ASNCIDR_ even if GeoDB finds _ASN_.
  • asn_use_dns ( 0 / 1 ) (default: 1) β€” Set to 0 to never allow DNS queries. Periodt. πŸ™…β™€οΈ

πŸ“ BAYES πŸ“

The bayes tokenizer will use ASN data for bayes calculations, which means it affects which BAYES_* rule will trigger for a particular message. No in-depth analysis of the usefulness of bayes tokenization of ASN data has been performed. That's just the situation, bestie. 😭


🌸 SEE ALSO 🌸


okay that's the whole page, you're welcome πŸ’– this was Mail::...in::ASN(3pm) from the User Contributed Perl Documentation, and it's running on perl v5.40.1, dated 2026-07-23. go forth and look up those ASNs, you've got this 🫢✨

πŸ“¦ where this page comes from