Files
whois/patch.diff
Olaf Baumert 34c631a06d Initial commit: mwhois with SCION AS support and decimal AS conversion
Based on mwhois by Antonios A. Chariton
Modifications for SCION AS support by Olaf Baumert, Axpo Systems AG
2025-06-03 11:01:02 +00:00

131 lines
3.9 KiB
Diff

diff --git a/mwhoisd b/mwhoisd
index 0000000..6e21fcc 100755
--- a/mwhoisd
+++ b/mwhoisd
@@ -54,7 +54,7 @@ def isDomain(qr):
if(len(qr.split(".")) == 1):
return False
zones = qr.split(".")
- ac = re.compile("^[a-z0-9\.-]+\n")
+ ac = re.compile(r"^[a-z0-9\.-]+\n")
for zone in zones:
if(zone == ""):
return False
@@ -66,6 +66,13 @@ def isDomain(qr):
return False
return True
+# Check if the input is a valid SCION AS identifier
+def isAS(qr):
+ # Check if format matches SCION AS identifier (e.g., "2:2:0")
+ if re.match(r'^\d+:\d+:\d+$', qr):
+ return True
+ return False
+
# Check if an IP belongs to a CIDR IP block
def isIPinCIDR(ip, network):
return IPAddress(ip) in IPNetwork(network)
@@ -76,14 +83,16 @@ while True:
while True:
query = con.recv(MAX_QUERY_SIZE)
if not query:
break
- log = log + query.replace("\r\n", "").replace("\n", "") + " - "
- query = sanitizeQuery(query)
+ # Decode bytes to string
+ query_str = query.decode('utf-8', errors='ignore')
+ log = log + query_str.replace("\r\n", "").replace("\n", "") + " - "
+ query = sanitizeQuery(query_str)
rsp = "# +-----------------------------------+" + n
- rsp = rsp + "# | DaKnObNET |" + n
+ rsp = rsp + "# | AXPO SYSTEMS AG |" + n
rsp = rsp + "# +-----------------------------------+" + n
rsp = rsp + "# | This query was served by mwhois |" + n
rsp = rsp + "# +-----------------------------------+" + n
rsp = rsp + n
if(isIP(query)):
@@ -115,13 +124,27 @@ while True:
rsp = rsp + n
rsp = rsp + "# Domain name was not found in the whois database" + n
log = log + " (Not found)" + n
+ elif(isAS(query)):
+ # WHOIS SCION AS
+ log = log + "SCION AS" + n
+
+ if os.path.exists("db/as/" + query):
+ dd = open("db/as/" + query, "r")
+ rsp = rsp + dd.read()
+ dd.close()
+ found = True
+ log = log + n
+ else:
+ rsp = rsp + n
+ rsp = rsp + "# SCION AS was not found in the whois database" + n
+ log = log + " (Not found)" + n
else:
# Unrecognized
log = log + "Unrecognized" + n
rsp = rsp + n
- rsp = rsp + "# Error. Unknown query type. Query is not IPv4 or Domain" + n
- con.send(rsp)
+ rsp = rsp + "# Error. Unknown query type. Query is not IPv4, Domain or SCION AS" + n
+ # Encode string to bytes before sending
+ con.send(rsp.encode('utf-8'))
con.close()
if(LOGFILE!=""):
# Save to logs
diff --git a/add-as b/add-as
new file mode 100755
index 0000000..05f0df7
--- /dev/null
+++ b/add-as
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+# Use this file to add SCION AS entries to the whois database
+
+import os
+import json
+
+# 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):
+ print("Invalid SCION AS Identifier format. Expected format: ISD:AS:Instance (e.g. 2:2:0)")
+ exit(1)
+
+# Get AS details
+isd = input("Enter ISD: ")
+as_decimal = input("Enter AS decimal value: ")
+organization = input("Enter Organization: ")
+country = input("Enter Country Code: ")
+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 += "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.")