-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions
57 lines (41 loc) · 1.24 KB
/
functions
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
#!/bin/bash
# proxy_port(container, service, from, to)
function add_proxy_port {
lxc config device add ${1} ${2} proxy \
listen=tcp:${3} \
connect=tcp:${4} \
nat=true
return $?
}
# Call with a hostname to get an IP address back
function dns_check_A {
local IP="UNRESOLVED"
if [ -x /usr/bin/host ]; then
IP=$(host -4 ${1} | grep ${1} | cut -d' ' -f 4)
else
IP=$(systemd-resolve ${1} -4 | grep ${1} | cut -d' ' -f 2)
fi
echo ${IP}
}
# Call with a domain, get the highest priority MX host.
function dns_check_MX {
local MX="UNRESOLVED"
if [ -x /usr/bin/host ]; then
MX=$(host -t mx ${1}|cut -d' ' -f 6-|sort -n|head -1|cut -d' ' -f 2)
else
MX=$(systemd-resolve -t mx ${1}|grep ${1}|cut -d' ' -f 4-|sort -n|head -1|cut -d' ' -f 2)
fi
# Return the response with any trailing '.' removed.
echo ${MX%.}
}
# Call with an IP address, and get the PTR host back
function dns_check_PTR {
local PTR="UNRESOLVED"
if [ -x /usr/bin/host ]; then
PTR=$(host ${1}|cut -d' ' -f 5)
else
PTR=$(systemd-resolve ${1}|grep 'link:'|cut -d' ' -f 2)
fi
# Return the response with any trailing '.' removed.
echo ${PTR%.}
}