mirror of
https://git.photon.obnh.io/AXSY/whois.git
synced 2026-03-12 18:01:32 +00:00
fix: Correct SCION AS to decimal conversion logic
- Remove incorrect ISD:AS:Instance interpretation - SCION AS format is three 16-bit hex values (48-bit total) - Only convert to decimal if result is within BGP range (0 to 2^32-1) - Example: 0:1:f = (0<<32) + (1<<16) + 15 = 65551 - AS numbers like 2:0:17 exceed BGP range and remain in hex format
This commit is contained in:
35
add-as
35
add-as
@@ -7,39 +7,30 @@ import json
|
|||||||
|
|
||||||
# Function to convert SCION AS to decimal if in BGP range
|
# Function to convert SCION AS to decimal if in BGP range
|
||||||
def scion_as_to_decimal(as_id):
|
def scion_as_to_decimal(as_id):
|
||||||
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)"""
|
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)
|
||||||
|
|
||||||
|
SCION AS format uses 16-bit : separated lowercase hex encoding.
|
||||||
|
Examples:
|
||||||
|
- 0:0:0 -> 0
|
||||||
|
- 0:1:f -> 65551
|
||||||
|
- 2:2:0 -> 131584
|
||||||
|
"""
|
||||||
# Handle plain decimal AS numbers
|
# Handle plain decimal AS numbers
|
||||||
if ':' not in as_id:
|
if ':' not in as_id:
|
||||||
return as_id
|
return as_id
|
||||||
|
|
||||||
# Parse SCION format
|
# Parse SCION AS format (colon-separated hex values)
|
||||||
parts = as_id.split(':')
|
parts = as_id.split(':')
|
||||||
|
|
||||||
# Check if this looks like ISD:AS:Instance format (first part is single digit ISD)
|
# Convert hex parts to decimal
|
||||||
if len(parts) == 3 and len(parts[0]) == 1 and parts[0].isdigit():
|
# Each part represents 16 bits, combine them into a single number
|
||||||
# ISD:AS:Instance format - convert the AS part (middle) and instance (last)
|
|
||||||
try:
|
|
||||||
# AS is 16-bit hex, instance is 16-bit hex
|
|
||||||
# Combine them as 32-bit number: AS << 16 | Instance
|
|
||||||
as_num = int(parts[1], 16)
|
|
||||||
instance = int(parts[2], 16)
|
|
||||||
total = (as_num << 16) | instance
|
|
||||||
|
|
||||||
if 0 <= total <= 0xFFFFFFFF: # BGP AS range
|
|
||||||
return str(total)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# For standard colon-separated hex format (e.g., 0:1:f)
|
|
||||||
# Each part is up to 16 bits
|
|
||||||
try:
|
try:
|
||||||
total = 0
|
total = 0
|
||||||
for part in parts:
|
for part in parts:
|
||||||
total = (total << 16) + int(part, 16)
|
total = (total << 16) + int(part, 16)
|
||||||
|
|
||||||
# Check if in BGP AS range
|
# Check if in BGP AS range (0 to 2^32-1)
|
||||||
if 0 <= total <= 0xFFFFFFFF: # 2^32 - 1
|
if 0 <= total <= 0xFFFFFFFF:
|
||||||
return str(total)
|
return str(total)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
35
add-as-batch
35
add-as-batch
@@ -12,39 +12,30 @@ os.system("mkdir -p db/as")
|
|||||||
|
|
||||||
# Function to convert SCION AS to decimal if in BGP range
|
# Function to convert SCION AS to decimal if in BGP range
|
||||||
def scion_as_to_decimal(as_id):
|
def scion_as_to_decimal(as_id):
|
||||||
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)"""
|
"""Convert SCION AS format to decimal if in BGP AS range (0 - 2^32-1)
|
||||||
|
|
||||||
|
SCION AS format uses 16-bit : separated lowercase hex encoding.
|
||||||
|
Examples:
|
||||||
|
- 0:0:0 -> 0
|
||||||
|
- 0:1:f -> 65551
|
||||||
|
- 2:2:0 -> 131584
|
||||||
|
"""
|
||||||
# Handle plain decimal AS numbers
|
# Handle plain decimal AS numbers
|
||||||
if ':' not in as_id:
|
if ':' not in as_id:
|
||||||
return as_id
|
return as_id
|
||||||
|
|
||||||
# Parse SCION format
|
# Parse SCION AS format (colon-separated hex values)
|
||||||
parts = as_id.split(':')
|
parts = as_id.split(':')
|
||||||
|
|
||||||
# Check if this looks like ISD:AS:Instance format (first part is single digit ISD)
|
# Convert hex parts to decimal
|
||||||
if len(parts) == 3 and len(parts[0]) == 1 and parts[0].isdigit():
|
# Each part represents 16 bits, combine them into a single number
|
||||||
# ISD:AS:Instance format - convert the AS part (middle) and instance (last)
|
|
||||||
try:
|
|
||||||
# AS is 16-bit hex, instance is 16-bit hex
|
|
||||||
# Combine them as 32-bit number: AS << 16 | Instance
|
|
||||||
as_num = int(parts[1], 16)
|
|
||||||
instance = int(parts[2], 16)
|
|
||||||
total = (as_num << 16) | instance
|
|
||||||
|
|
||||||
if 0 <= total <= 0xFFFFFFFF: # BGP AS range
|
|
||||||
return str(total)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# For standard colon-separated hex format (e.g., 0:1:f)
|
|
||||||
# Each part is up to 16 bits
|
|
||||||
try:
|
try:
|
||||||
total = 0
|
total = 0
|
||||||
for part in parts:
|
for part in parts:
|
||||||
total = (total << 16) + int(part, 16)
|
total = (total << 16) + int(part, 16)
|
||||||
|
|
||||||
# Check if in BGP AS range
|
# Check if in BGP AS range (0 to 2^32-1)
|
||||||
if 0 <= total <= 0xFFFFFFFF: # 2^32 - 1
|
if 0 <= total <= 0xFFFFFFFF:
|
||||||
return str(total)
|
return str(total)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user