feat: link ASN to bgp.tools page

This commit is contained in:
NetworkCats
2026-03-06 05:27:49 +08:00
parent d9f7cd61f9
commit d256834dd2
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -37,6 +37,7 @@ struct IndexTemplate {
site_domain: Arc<str>,
css_version: u64,
asn: String,
asn_number: Option<u32>,
org: String,
country: String,
city: String,
@@ -182,10 +183,12 @@ fn wants_json(headers: &HeaderMap) -> bool {
.is_some_and(|v| v.contains("application/json"))
}
fn asn_number(info: &IpInfo) -> Option<u32> {
info.asn.as_ref().and_then(|a| a.autonomous_system_number)
}
fn format_asn(info: &IpInfo) -> String {
info.asn
.as_ref()
.and_then(|a| a.autonomous_system_number)
asn_number(info)
.map(|n| format!("AS{n}"))
.unwrap_or_default()
}
@@ -557,6 +560,7 @@ pub async fn root(
site_domain: state.site_domain.clone(),
css_version: static_assets::asset_version("style.css"),
asn: format_asn(&info),
asn_number: asn_number(&info),
org: format_org(&info).to_owned(),
country: format_country(&info, locale).to_owned(),
city: format_city(&info, locale).to_owned(),
+1 -1
View File
@@ -39,7 +39,7 @@
{% if !asn.is_empty() %}
<tr>
<th scope="row">{{ t_asn }}</th>
<td>{{ asn }}</td>
<td>{% if let Some(n) = asn_number %}<a href="https://bgp.tools/as/{{ n }}" target="_blank" rel="noopener noreferrer">{{ asn }}</a>{% else %}{{ asn }}{% endif %}</td>
</tr>
{% endif %}
{% if !org.is_empty() %}