Files
Debain-repos/AiO_Container/code/momoid.py

78 lines
2.2 KiB
Python
Raw Normal View History

2026-04-03 23:00:43 +02:00
# https://dnspython.readthedocs.io/en/latest/
import subprocess
from typing import Optional, Annotated
# import dns, dns.resolver
class Momoid:
def __init__(
self,
resolverIPaddr: Annotated[int, "IP Address of a DNS server"] = "1.1.1.1",
DoH: Annotated[bool, "If DNS over HTTPS should be used"] = True
):
if DoH:
self.__MOMOID_CMD = ["dig", "+short", "+https", f"@{resolverIPaddr}"]
else:
self.__MOMOID_CMD = ["dig", "+short", f"@{resolverIPaddr}"]
def recordA(self, domain: Annotated[str, "Domain to resolve to a A record"]) -> list:
if not domain:
return 0
outpt = subprocess.run([*self.__MOMOID_CMD, domain, "A"], capture_output=True, text=True)
if outpt.stdout.strip() == "":
return 0
else:
outList = outpt.stdout.strip().split("\n")
return outList
def recordAAAA(self, domain: Annotated[str, "Domain to resolve to a AAAA record"]) -> list:
if not domain:
return 0
outpt = subprocess.run([*self.__MOMOID_CMD, domain, "AAAA"], capture_output=True, text=True)
if outpt.stdout.strip() == "":
return 0
else:
outList = outpt.stdout.strip().split("\n")
return outList
def recordPTR(self, domain: Annotated[str, "Domain to resolve to a PTR record"]) -> list:
# 1.2.3.4 -> 4.3.2.1.in-addr.arpa
if not domain:
return 0
outpt = subprocess.run([*self.__MOMOID_CMD, domain, "PTR"], capture_output=True, text=True)
if outpt.stdout.strip() == "":
return 0
else:
outList = outpt.stdout.strip().split("\n")
return outList
def __ipv4ToPTR(ipString: Annotated[str, "a string with an IPv4 address"]):
arpa = "in-addr.arpa"
ipList = ipa.split(".")
ipList.reverse()
outstr = ""
for thing in ipList:
outstr += thing
outstr += "."
return outstr + arpa
thing = Momoid("1.1.1.1", False)
x = thing.recordA("shupogaki.org")
print(x)