InProgress Revamp of domainLookup
This commit is contained in:
77
AiO_Container/code/momoid.py
Normal file
77
AiO_Container/code/momoid.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user