Skip to content

Commit e5338b3

Browse files
committed
add -4 switch (CLI) / FORCE_IPV4 option (.asnrc) to force ipv4 connectivity on dual-stack hosts (closes #93, implements #43)
1 parent 75b1c81 commit e5338b3

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ where `TARGET` can be one of the following:
578578

579579
>*.asnrc option equivalent: `MTR_TRACING=true` (default: `true`)*
580580
581+
* `-4`
582+
583+
* forces IPv4-only connectivity during traces and in server mode (only useful on dual-stack hosts)
584+
585+
>*.asnrc option equivalent: `FORCE_IPV4=true` (default: `false`)*
586+
581587
* `-d`
582588

583589
* enables detailed trace mode (more info below)
@@ -711,6 +717,7 @@ MTR_TRACING=true
711717
ADDITIONAL_INETNUM_LOOKUP=true
712718
DETAILED_TRACE=false
713719
MTR_ROUNDS=5
720+
FORCE_IPV4=false
714721
MAX_CONCURRENT_SHODAN_REQUESTS=10
715722
SHODAN_SHOW_TOP_N=5
716723
MONOCHROME_MODE=false

asn

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# │ (Launch the script without parameters or visit the project's homepage for usage info)│
1313
# ╰──────────────────────────────────────────────────────────────────────────────────────╯
1414

15-
ASN_VERSION="0.79.0"
15+
ASN_VERSION="0.80.0"
1616
ASN_LOGFILE="$HOME/asndebug.log"
1717

1818
# ╭──────────────────╮
@@ -1039,8 +1039,12 @@ TraceASPath(){
10391039
BoxHeader "$headermsg"
10401040
# check if we're trying to trace an IPv6 from an IPv4-only box
10411041
echo "$host_to_trace" | grep -q ':' && is_ipv6=true || is_ipv6=false
1042-
if [ "$is_ipv6" = true ] && [ "$HAVE_IPV6" = false ]; then
1043-
PrintErrorAndExit "Error: cannot trace an IPv6 from this IPv4-only host!"
1042+
if [ "$is_ipv6" = true ]; then
1043+
if [ "$FORCE_IPV4" = true ]; then
1044+
PrintErrorAndExit "Error: cannot trace an IPv6 when FORCE_IPV4=true (hint: check .asnrc or don't pass the -4 option)"
1045+
elif [ "$HAVE_IPV6" = false ]; then
1046+
PrintErrorAndExit "Error: cannot trace an IPv6 from this IPv4-only host!"
1047+
fi
10441048
fi
10451049
echo ""
10461050
StatusbarMessage "Collecting trace data to ${bluebg}${host_to_trace}${lightgreybg}"
@@ -3028,8 +3032,9 @@ AsnServerListener(){
30283032
# Handle all non-GCP cases
30293033
# prepare the bookmarklet URL and the appropriate notation for the server's bind address:port
30303034
if [ "$ASN_SRV_BINDADDR" = "0.0.0.0" ]; then
3035+
FORCE_IPV4=true
30313036
# discover our IPv4 WAN IP if we already determined we're on an IPv6-capable host but the user wants to bind to 0.0.0.0
3032-
[[ "$HAVE_IPV6" = true ]] && WhatIsMyIP "true"
3037+
[[ "$HAVE_IPV6" = true ]] && WhatIsMyIP
30333038
if grep -q ':' <<<"$local_wanip"; then
30343039
INTERNAL_ASNSERVER_ADDRESS="[$local_wanip]:$ASN_SRV_BINDPORT"
30353040
else
@@ -3167,8 +3172,8 @@ StatusbarMessage() { # invoke without parameters to delete the status bar messag
31673172
}
31683173

31693174
WhatIsMyIP() {
3170-
# if an argument was passed, force IPv4 lookup (and skip "only check once" check)
3171-
if [ -n "$1" ]; then
3175+
# if FORCE_IPV4=true, force IPv4 lookup (and skip "only check once" check)
3176+
if [ "$FORCE_IPV4" = true ]; then
31723177
local_wanip=$(docurl -m10 -s -4 "https://ifconfig.co")
31733178
else
31743179
# only lookup local WAN IP once
@@ -3432,6 +3437,7 @@ CheckPrerequisites() {
34323437
DebugPrint "${dim}${white}$token: ${green}✓ OK${white}"
34333438
fi
34343439
done
3440+
[[ "$FORCE_IPV4" = true ]] && DebugPrint "${dim}${white}Forcing IPv4-only connectivity (FORCE_IPV4=true)"
34353441
fi
34363442
fi
34373443
CoreutilsFixup
@@ -4131,6 +4137,7 @@ peeringdb_ipv6_dataset=""
41314137
[[ -r "/etc/services" ]] && WELL_KNOWN_PORTS=$(cat /etc/services) || WELL_KNOWN_PORTS=""
41324138

41334139
# default options (configurable via $HOME/.asnrc)
4140+
FORCE_IPV4=false
41344141
MTR_TRACING=true
41354142
ADDITIONAL_INETNUM_LOOKUP=true
41364143
DETAILED_TRACE=false
@@ -4210,7 +4217,7 @@ json_resultcount=0
42104217
# in this mode, getopts sets optchar to:
42114218
# '?' -> unknown option
42124219
# ':' -> missing mandatory parameter to the option
4213-
optspec=":hvmljJsgn:t:d:o:a:c:u:"
4220+
optspec=":hvmljJsg4n:t:d:o:a:c:u:"
42144221

42154222
FORCE_ORGSEARCH=false
42164223
SUGGEST_SEARCH=false
@@ -4295,6 +4302,11 @@ while getopts "$optspec" optchar; do {
42954302
#shellcheck disable=SC2218
42964303
GetFullParamsFromCurrentPosition "$@"
42974304
;;
4305+
"4")
4306+
FORCE_IPV4=true
4307+
#shellcheck disable=SC2218
4308+
GetFullParamsFromCurrentPosition "$@"
4309+
;;
42984310
"m")
42994311
MONOCHROME_MODE=true
43004312
;;

asn.1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH ASN 1 "August 2025" "0.79.0" "User Commands"
1+
.TH ASN 1 "August 2025" "0.80.0" "User Commands"
22
.SH NAME
33
asn \- ASN / RPKI validity / BGP stats / IPv4v6 / Prefix / ASPath / Organization / IP reputation lookup tool
44
.SH SYNOPSIS
@@ -18,6 +18,13 @@ Enable AS path trace to the
1818
.B TARGET
1919
(this is the default behavior)
2020
.TP
21+
\fB-4\fR
22+
.B (force IPv4 connectivity)
23+
.br
24+
Force the tool to only utilize the IPv4 stack when tracing the
25+
.B TARGET
26+
or when running in server mode (only useful on dual-stack hosts)
27+
.TP
2128
\fB-n\fR
2229
.B (no trace|no additional INETNUM lookups)
2330
.br

0 commit comments

Comments
 (0)