diff options
Diffstat (limited to 'generalresearch/models/network/rdns/command.py')
| -rw-r--r-- | generalresearch/models/network/rdns/command.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/generalresearch/models/network/rdns/command.py b/generalresearch/models/network/rdns/command.py new file mode 100644 index 0000000..e9d5bfd --- /dev/null +++ b/generalresearch/models/network/rdns/command.py @@ -0,0 +1,33 @@ +import subprocess + +from generalresearch.models.network.rdns.parser import parse_rdns_output +from generalresearch.models.network.rdns.result import RDNSResult + + +def run_rdns(ip: str) -> RDNSResult: + args = build_rdns_command(ip).split(" ") + proc = subprocess.run( + args, + capture_output=True, + text=True, + check=False, + ) + raw = proc.stdout.strip() + return parse_rdns_output(ip, raw) + + +def build_rdns_command(ip: str): + # e.g. dig +noall +answer -x 1.2.3.4 + return " ".join(["dig", "+noall", "+answer", "-x", ip]) + + +def get_dig_version() -> str: + proc = subprocess.run( + ["dig", "-v"], + capture_output=True, + text=True, + check=False, + ) + # e.g. DiG 9.18.39-0ubuntu0.22.04.2-Ubuntu + ver_str = proc.stderr.strip() + return ver_str.split("-", 1)[0].split(" ", 1)[1] |
