-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdig.py
More file actions
68 lines (56 loc) · 1.86 KB
/
dig.py
File metadata and controls
68 lines (56 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""Issue DNS requests through Albert."""
from albert import *
import subprocess
import ipaddress
__title__ = "Dig"
__version__ = "0.4.1"
__triggers__ = "dig"
__authors__ = "Benjamin Altpeter"
defaultIcon = iconLookup("network-server")
def handleQuery(query):
if not query.isTriggered:
return
results = []
args = query.string.split()
if len(args) > 0:
try:
cmd = ["dig", "+noall", "+noclass", "+answer"]
if isIp(args[0]): cmd.append("-x")
cmd.append(args[0])
if len(args) > 1: cmd.append(args[1])
sp = subprocess.run(cmd, stdout=subprocess.PIPE)
output = list(map(lambda line: line.split(), sp.stdout.decode("utf-8").split("\n")))
for line in output:
if len(line) > 3:
value = " ".join(line[3:])
results.append(
Item(
id=__title__,
icon=defaultIcon,
text=value + " :: " + line[2],
subtext=line[0] + " :: TTL = " + line[1],
completion=value,
actions=[
ClipAction("Copy value", value)
]
)
)
except:
pass
else:
results.append(
Item(
id=__title__,
icon=defaultIcon,
text="Enter your query to lookup DNS records.",
subtext="First argument is the domain or IP, (optional) second argument is the record type.",
completion=query.rawString
)
)
return results
def isIp(ip):
try:
ipaddress.ip_address(ip)
return True
except: return False