mirror of
https://git.photon.obnh.io/AXSY/whois.git
synced 2025-12-11 04:39:15 +00:00
- 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
87 lines
2.6 KiB
Python
Executable File
87 lines
2.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
# Use this file to add SCION AS entries to the whois database
|
|
|
|
import os
|
|
import json
|
|
|
|
# Function to convert SCION AS to decimal if in BGP range
|
|
def scion_as_to_decimal(as_id):
|
|
"""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
|
|
if ':' not in as_id:
|
|
return as_id
|
|
|
|
# Parse SCION AS format (colon-separated hex values)
|
|
parts = as_id.split(':')
|
|
|
|
# Convert hex parts to decimal
|
|
# Each part represents 16 bits, combine them into a single number
|
|
try:
|
|
total = 0
|
|
for part in parts:
|
|
total = (total << 16) + int(part, 16)
|
|
|
|
# Check if in BGP AS range (0 to 2^32-1)
|
|
if 0 <= total <= 0xFFFFFFFF:
|
|
return str(total)
|
|
except ValueError:
|
|
pass
|
|
|
|
return ""
|
|
|
|
# Ensure the AS database directory exists
|
|
os.system("mkdir -p db/as")
|
|
|
|
as_id = input("Enter SCION AS Identifier (format ISD:AS:Instance, e.g. 2:2:0): ")
|
|
|
|
# Validate AS ID format
|
|
import re
|
|
if not re.match(r'^\d+:\d+:\d+$', as_id) and not re.match(r'^\d+$', as_id):
|
|
print("Invalid SCION AS Identifier format. Expected format: ISD:AS:Instance (e.g. 2:2:0) or just AS number (e.g. 60284)")
|
|
exit(1)
|
|
|
|
# Get AS details
|
|
isd = input("Enter ISD: ")
|
|
# Automatically calculate decimal representation
|
|
as_decimal = scion_as_to_decimal(as_id)
|
|
if as_decimal:
|
|
print(f"AS decimal value (auto-calculated): {as_decimal}")
|
|
else:
|
|
as_decimal = input("Enter AS decimal value (not in BGP range, press Enter to skip): ")
|
|
|
|
organization = input("Enter Organization: ")
|
|
country = input("Enter Country Code: ")
|
|
uid = input("Enter UID (e.g. CHE-123.456.789): ")
|
|
status = input("Enter Status (ASSIGNED/ALLOCATED): ")
|
|
description = input("Enter Description: ")
|
|
contact = input("Enter Contact Email: ")
|
|
date_allocated = input("Enter Date Allocated (YYYY-MM-DD): ")
|
|
|
|
# Prepare AS data
|
|
n = "\r\n"
|
|
body = "% SCION AS WHOIS Information" + n + n
|
|
body += "AS Identifier: " + as_id + n
|
|
body += "ISD: " + isd + n
|
|
body += "AS decimal: " + as_decimal + n
|
|
body += "Organization: " + organization + n
|
|
body += "Country: " + country + n
|
|
body += "UID: " + uid + n
|
|
body += "Status: " + status + n
|
|
body += "Description: " + description + n
|
|
body += "Contact: " + contact + n
|
|
body += "DateAllocated: " + date_allocated + n
|
|
|
|
# Save to file
|
|
d = open("db/as/" + as_id, "w+")
|
|
d.write(body)
|
|
d.close()
|
|
print("Done! SCION AS record added successfully.")
|