-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolver
More file actions
executable file
·89 lines (89 loc) · 1.97 KB
/
resolver
File metadata and controls
executable file
·89 lines (89 loc) · 1.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
DOMAIN_NAME="$1"
QUERY_TYPE="$2"
if [ "$QUERY_TYPE" == "reverse" ]
then
dig -x $DOMAIN_NAME > output
else
dig $DOMAIN_NAME $QUERY_TYPE > output
fi
FILE="output"
answer="["
authority="["
additional="["
details="{"
fanswer=FALSE
fauth=FALSE
fadd=FALSE
while read line; do
case $line in
"")
continue;;
";; ANSWER SECTION:")
fanswer=TRUE;;
";; AUTHORITY SECTION:")
fanswer=FALSE
fauth=TRUE;;
";; ADDITIONAL SECTION:")
fanswer=FALSE
fauth=FALSE
fadd=TRUE;;
";; Query time:"*)
fanswer=FALSE
fauth=FALSE
fadd=FALSE
y=( $line )
details="$details `echo -e "\\"time\\" : \\"${y[3]} ${y[4]}\\","`";;
";; WHEN:"*)
y=( $line )
details="$details `echo -e "\\"timestamp\\" : \\"${y[2]} ${y[3]} ${y[4]} ${y[5]} ${y[6]}\\","`";;
*)
if [ "$fanswer" == "TRUE" ]
then
y=( $line )
name=${y[0]}
if [ "$QUERY_TYPE" == "MX" ]
then
answer="$answer`echo "{\\"name\\" : \\"${name::-1}\\", \\"type\\" : \\"${y[3]}\\", \\"result\\" : \\"${y[4]} ${y[5]}\\"}"`,"
else
answer="$answer`echo "{\\"name\\" : \\"${name::-1}\\", \\"type\\" : \\"${y[3]}\\", \\"result\\" : \\"${y[4]}\\"}"`,"
fi
elif [ "$fauth" == "TRUE" ]
then
y=( $line )
name=${y[0]}
result=${y[4]}
authority="$authority`echo "{\\"name\\" : \\"${name::-1}\\", \\"type\\" : \\"${y[3]}\\", \\"result\\" : \\"${result::-1}\\"}"`,"
elif [ "$fadd" == "TRUE" ]
then
y=( $line )
name=${y[0]}
additional="$additional`echo "{\\"name\\" : \\"${name::-1}\\", \\"type\\" : \\"${y[3]}\\", \\"result\\" : \\"${y[4]}\\"}"`,"
fi
esac
done < "$FILE"
if [ "$answer" != "[" ]
then
answer="${answer::-1}]"
else
answer="[]"
fi
if [ "$authority" != "[" ]
then
authority="${authority::-1}]"
else
authority="[]"
fi
if [ "$additional" != "[" ]
then
additional="${additional::-1}]"
else
additional="[]"
fi
if [ "$details" != "{" ]
then
details="${details::-1}}"
else
details="{}"
fi
echo "{\"answer\" : $answer, \"authority\" : $authority, \"additional\" : $additional, \"details\" : $details}"