mirror of
https://github.com/mii443/sindan-client.git
synced 2025-08-22 16:25:41 +00:00
Released version 3.0.0
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
# SINDAN Configuration file
|
||||
# version 2.4.0
|
||||
# version 3.0.0
|
||||
|
||||
# PID file
|
||||
readonly PIDFILE=/tmp/sindan.pid
|
||||
|
||||
# lock file
|
||||
readonly LOCKFILE=/tmp/sindan.isrunning
|
||||
readonly LOCKFILE_SENDLOG=/tmp/sendlog.isrunning
|
||||
|
||||
# result parameters
|
||||
@ -49,8 +51,8 @@ readonly V4WEB_SRVS="www.wide.ad.jp,www.yahoo.co.jp"
|
||||
readonly V6WEB_SRVS="www.wide.ad.jp,www.google.co.jp"
|
||||
|
||||
# servers for ssh servers (format: <FQDN>_<keytype>)
|
||||
readonly V4SSH_SRVS="fluentd.sindan-net.com_ed25519,www.wide.ad.jp_rsa"
|
||||
readonly V6SSH_SRVS="fluentd.sindan-net.com_ed25519,www.wide.ad.jp_rsa"
|
||||
readonly V4SSH_SRVS="fluentd.sindan-net.com_ed25519"
|
||||
readonly V6SSH_SRVS="fluentd.sindan-net.com_ed25519"
|
||||
|
||||
# servers for portscan
|
||||
readonly PS_SRVS4="target.sindan-net.com"
|
||||
|
2314
linux/sindan.sh
2314
linux/sindan.sh
File diff suppressed because it is too large
Load Diff
111
linux/sindan_func0.sh
Executable file
111
linux/sindan_func0.sh
Executable file
@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
# sindan_func0.sh
|
||||
|
||||
## Hardware Layer functions
|
||||
|
||||
|
||||
# Get OS information.
|
||||
function get_os() {
|
||||
if which lsb_release > /dev/null 2>&1; then
|
||||
lsb_release -ds
|
||||
else
|
||||
grep PRETTY_NAME /etc/*-release |
|
||||
awk -F\" '{print $2}'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get hardware information.
|
||||
function get_hw_info() {
|
||||
if [ -e /proc/device-tree/model ]; then
|
||||
awk 1 /proc/device-tree/model | tr -d '\0'
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get CPU frequency infotmation.
|
||||
function get_cpu_freq() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_cpu_freq <os>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if echo $1 | grep Raspbian > /dev/null 2>&1; then
|
||||
vcgencmd measure_clock arm |
|
||||
awk -F= '{print $2}'
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get CPU voltage information.
|
||||
function get_cpu_volt() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_cpu_volt <os>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if echo $1 | grep Raspbian > /dev/null 2>&1; then
|
||||
vcgencmd measure_volts core |
|
||||
sed -n 's/^volt=\([0-9\.]*\).*$/\1/p'
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get CPU temperature information.
|
||||
function get_cpu_temp() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_cpu_temp <os>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if echo $1 | grep Raspbian > /dev/null 2>&1; then
|
||||
vcgencmd measure_temp |
|
||||
sed -n 's/^temp=\([0-9\.]*\).*$/\1/p'
|
||||
elif [ -f /sys/class/thermal/thermal_zone0/temp ]; then
|
||||
echo "scale=3; $(cat /sys/class/thermal/thermal_zone0/temp) / 1000" |
|
||||
bc
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get system clock status.
|
||||
function get_clock_state() {
|
||||
if which timedatectl > /dev/null 2>&1; then
|
||||
timedatectl |
|
||||
sed -n 's/.*System clock synchronized: \([a-z]*\).*$/\1/p'
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get the time souece of the system clock.
|
||||
function get_clock_src() {
|
||||
if which timedatectl > /dev/null 2>&1; then
|
||||
use_timesyncd=$(timedatectl |
|
||||
grep -e "NTP service: active" \
|
||||
-e "systemd-timesyncd.service active: yes")
|
||||
if [ -n "$use_timesyncd" ]; then
|
||||
systemctl status systemd-timesyncd |
|
||||
grep Status |
|
||||
sed 's/^[ \t]*//'
|
||||
else
|
||||
if [ -e /run/ntpd.pid ]; then
|
||||
ntpq -p | grep -e ^o -e ^*
|
||||
elif [ -e /run/chronyd.pid ]; then
|
||||
chronyc sources | grep "\^\*"
|
||||
else
|
||||
echo 'using unknown time synclonization service.'
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
496
linux/sindan_func1.sh
Executable file
496
linux/sindan_func1.sh
Executable file
@ -0,0 +1,496 @@
|
||||
#!/bin/bash
|
||||
# sindan_func1.sh
|
||||
|
||||
## Datalink Layer functions
|
||||
|
||||
# Get the interface name.
|
||||
function get_ifname() {
|
||||
echo "$IFNAME"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Stop the interface.
|
||||
# do_ifdown <ifname> <iftype>
|
||||
function do_ifdown() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: do_ifdown <ifname> <iftype>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
local wwan_dev
|
||||
if [ "$2" = "WWAN" ]; then
|
||||
wwan_dev=$(get_wwan_port "$1")
|
||||
nmcli device disconnect "$wwan_dev"
|
||||
else
|
||||
nmcli device disconnect "$1"
|
||||
fi
|
||||
elif which ifconfig > /dev/null 2>&1; then
|
||||
ifconfig "$1" down
|
||||
else
|
||||
ip link set "$1" down
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Activate the interface.
|
||||
# do_ifup <ifname> <iftype>
|
||||
function do_ifup() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: do_ifup <ifname> <iftype>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
local wwan_dev
|
||||
if [ "$2" = "WWAN" ]; then
|
||||
wwan_dev=$(get_wwan_port "$1")
|
||||
nmcli device connect "$wwan_dev"
|
||||
else
|
||||
nmcli device connect "$1"
|
||||
fi
|
||||
elif which ifconfig > /dev/null 2>&1; then
|
||||
ifconfig "$1" up
|
||||
else
|
||||
ip link set "$1" up
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get the interface status.
|
||||
# get_ifstatus <ifname> <iftype>
|
||||
function get_ifstatus() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ifstatus <ifname> <iftype>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local status; local path; local modem_info
|
||||
if [ "$2" = "WWAN" ]; then
|
||||
for path in $(mmcli -L | awk '{print $1}' | tr '\n' ' '); do
|
||||
modem_info=$(mmcli -m $path)
|
||||
if echo $modem_info | grep "$1" > /dev/null 2>&1; then
|
||||
status=$(echo "$modem_info" |
|
||||
awk 'BEGIN { #
|
||||
find=0 #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1 && match(line,/.*state:.*/)) { #
|
||||
split(line,s," ") #
|
||||
printf "%s", s[3] #
|
||||
exit #
|
||||
} else if (match(line,/^ Status.*/)) { #
|
||||
find=1 #
|
||||
} #
|
||||
} #
|
||||
}' |
|
||||
sed 's/\x1b\[[0-9;]*m//g')
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
status=$(cat /sys/class/net/"$1"/operstate)
|
||||
fi
|
||||
if [ "$status" = "up" ] || [ "$status" = "connected" ]; then
|
||||
echo "$status"; return 0
|
||||
else
|
||||
echo "$status"; return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get MTU of the interface.
|
||||
# get_ifmtu <ifname>
|
||||
function get_ifmtu() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ifmtu <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
cat /sys/class/net/"$1"/mtu
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get MAC address on the interface.
|
||||
# get_macaddr <ifname>
|
||||
function get_macaddr() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_macaddr <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
< /sys/class/net/"$1"/address tr "[:upper:]" "[:lower:]"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get media type of the interface.
|
||||
# get_mediatype <ifname>
|
||||
function get_mediatype() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_mediatype <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local speed; local duplex
|
||||
speed=$(cat /sys/class/net/"$1"/speed)
|
||||
duplex=$(cat /sys/class/net/"$1"/duplex)
|
||||
echo "${speed}_${duplex}"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get SSID using on the interface.
|
||||
# get_wlan_ssid <ifname>
|
||||
function get_wlan_ssid() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_ssid <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwgetid "$1" --raw
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get BSSID using on the interface.
|
||||
# get_wlan_bssid <ifname>
|
||||
function get_wlan_bssid() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_bssid <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwgetid "$1" --raw --ap |
|
||||
tr "[:upper:]" "[:lower:]"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get OUI of Access Point using on the interface.
|
||||
# get_wlan_apoui <ifname>
|
||||
function get_wlan_apoui() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_apoui <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwgetid "$1" --raw --ap |
|
||||
cut -d: -f1-3 |
|
||||
tr "[:upper:]" "[:lower:]"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get channel of WLAN using on the interface.
|
||||
# get_wlan_channel <ifname>
|
||||
function get_wlan_channel() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_channel <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwgetid "$1" --raw --channel
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get RSSI of WLAN using on the interface.
|
||||
# get_wlan_rssi <ifname>
|
||||
function get_wlan_rssi() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_rssi <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
grep "$1" /proc/net/wireless |
|
||||
awk '{print $4}' |
|
||||
sed 's/.$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get noise of WLAN using on the interface.
|
||||
# get_wlan_noise <ifname>
|
||||
function get_wlan_noise() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_noise <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
grep "$1" /proc/net/wireless |
|
||||
awk '{print $5}' |
|
||||
sed 's/.$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get quality of WLAN using on the interface.
|
||||
# get_wlan_quality <ifname>
|
||||
function get_wlan_quality() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_quality <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwconfig "$1" |
|
||||
sed -n 's/^.*Link Quality=\([0-9\/]*\).*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get current bit rate of WLAN using on the interface.
|
||||
# get_wlan_rate <ifname>
|
||||
function get_wlan_rate() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_rate <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
iwconfig "$1" |
|
||||
sed -n 's/^.*Bit Rate=\([0-9.]*\) Mb\/s.*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get the list of access points in range of the interface.
|
||||
# get_wlan_environment <ifname>
|
||||
function get_wlan_environment() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wlan_environment <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
echo "BSSID,Protocol,SSID,Channel,Quality,RSSI,Noise,BitRates"
|
||||
iwlist "$1" scanning |
|
||||
awk 'BEGIN { #
|
||||
find=0 #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/Protocol:.*/)) { #
|
||||
split(line,a,":") #
|
||||
printf ",%s", a[2] #
|
||||
} else if (match(line,/ESSID:.*/)) { #
|
||||
split(line,a,"\"") #
|
||||
printf ",%s", a[2] #
|
||||
} else if (match(line,/Channel [0-9]*/)) { #
|
||||
split(substr(line,RSTART,RLENGTH),a," ") #
|
||||
printf ",%s", a[2] #
|
||||
} else if (match(line,/Quality=.*/)) { #
|
||||
gsub(/=/," ",line) #
|
||||
split(line,a," ") #
|
||||
printf ",%s,%s,%s", a[2], a[5], a[9] #
|
||||
} else if (match(line,/Rates:[0-9.]* /)) { #
|
||||
split(substr(line,RSTART,RLENGTH),a,":") #
|
||||
printf ",%s\n", a[2] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/Address:.*/)) { #
|
||||
split(substr(line,RSTART,RLENGTH),a," ") #
|
||||
printf "%s", tolower(a[2]) #
|
||||
find=1 #
|
||||
} #
|
||||
} #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get port number of the WWAN interface.
|
||||
# get_wwan_port <ifname>
|
||||
function get_wwan_port() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wwan_port <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
for path in $(mmcli -L | awk '{print $1}' | tr '\n' ' '); do
|
||||
modem_info=$(mmcli -m $path)
|
||||
if echo $modem_info | grep "$1" > /dev/null 2>&1; then
|
||||
echo "$modem_info" |
|
||||
awk 'BEGIN { #
|
||||
find=0 #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1 && match(line,/.*primary port:.*/)) { #
|
||||
split(line,s," ") #
|
||||
printf "%s", s[4] #
|
||||
exit #
|
||||
} else if (match(line,/^ System.*/)) { #
|
||||
find=1 #
|
||||
} #
|
||||
} #
|
||||
}'
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Get the WWAN interface information.
|
||||
# get_wwan_info <ifname>
|
||||
function get_wwan_info() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wwan_info <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local modem_info; local bearer_info; local signal_info
|
||||
local threegpp_info
|
||||
for path in $(mmcli -L | awk '{print $1}' | tr '\n' ' '); do
|
||||
modem_info=$(mmcli -m $path)
|
||||
if echo $modem_info | grep "$1" > /dev/null 2>&1; then
|
||||
echo 'CELLULER INFO:'
|
||||
echo 'MODEM INFO:'
|
||||
echo "$modem_info"
|
||||
|
||||
for bearer in $(echo "$modem_info" |
|
||||
sed -n 's/^.*Bearer\/\([0-9]*\).*$/\1/p' |
|
||||
tr '\n' ' '); do
|
||||
bearer_info=$(mmcli -b $bearer)
|
||||
if echo $bearer_info | grep "$1" > /dev/null 2>&1; then
|
||||
echo 'BEARER INFO:'
|
||||
echo "$bearer_info"
|
||||
fi
|
||||
done
|
||||
|
||||
signal_info=$(mmcli -m $path --signal-get)
|
||||
if echo "$signal_info" |
|
||||
grep "refresh rate: 0 seconds" > /dev/null 2>&1; then
|
||||
mmcli -m $path --signal-setup=10 > /dev/null 2>&1
|
||||
signal_info=$(mmcli -m $path --signal-get)
|
||||
fi
|
||||
echo 'SIGNAL INFO:'
|
||||
echo "$signal_info"
|
||||
|
||||
threegpp_info=$(mmcli -m $path --location-get)
|
||||
echo '3GPP INFO:'
|
||||
echo "$threegpp_info"
|
||||
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Get various information of WWAN.
|
||||
# get_wwan_value <type> <cat> <name> <pos>
|
||||
# require get_wwan_info() data from STDIN.
|
||||
function get_wwan_value() {
|
||||
if [ $# -ne 4 ]; then
|
||||
echo "ERROR: get_wwan_value <type> <cat> <name> <pos>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v type="$1" -v cat="$2" -v name="$3" -v pos="$4" 'BEGIN { #
|
||||
find=0 #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1 || find==2) { #
|
||||
if (find==2 && line ~ name) { #
|
||||
split(line,s," ") #
|
||||
printf "%s", s[pos] #
|
||||
exit #
|
||||
} else if (line ~ cat) { #
|
||||
if (line ~ name) { #
|
||||
split(line,s," ") #
|
||||
printf "%s", s[pos+1] #
|
||||
exit #
|
||||
} #
|
||||
find=2 #
|
||||
} #
|
||||
} else if (line ~ type) { #
|
||||
find=1 #
|
||||
} #
|
||||
} #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get modem ID of WWAN.
|
||||
function get_wwan_modemid() {
|
||||
get_wwan_value 'MODEM INFO:' General 'dbus path:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get APN of WWAN.
|
||||
function get_wwan_apn() {
|
||||
get_wwan_value 'BEARER INFO:' Properties 'apn:' 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IP type of WWAN.
|
||||
function get_wwan_iptype() {
|
||||
get_wwan_value 'BEARER INFO:' Properties 'ip type:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get MTU of WWAN.
|
||||
function get_wwan_ifmtu() {
|
||||
get_wwan_value 'BEARER INFO:' 'IPv4 configuration' mtu: 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get interface type of WWAN.
|
||||
function get_wwan_iftype() {
|
||||
get_wwan_value 'MODEM INFO:' Status 'access tech:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get quality of WWAN.
|
||||
function get_wwan_quality() {
|
||||
get_wwan_value 'MODEM INFO:' Status 'signal quality:' 4 |
|
||||
sed 's/%//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IMEI of WWAN.
|
||||
function get_wwan_imei() {
|
||||
get_wwan_value 'MODEM INFO:' 3GPP imei: 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get operator name of WWAN.
|
||||
function get_wwan_operator() {
|
||||
get_wwan_value 'MODEM INFO:' 3GPP 'operator name:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get operator ID of WWAN.
|
||||
function get_wwan_mmcmnc() {
|
||||
get_wwan_value 'MODEM INFO:' 3GPP 'operator id:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get RSSI of WWAN.
|
||||
function get_wwan_rssi() {
|
||||
get_wwan_value 'SIGNAL INFO:' LTE 'rssi:' 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get RSRQ of WWAN.
|
||||
function get_wwan_rsrq() {
|
||||
get_wwan_value 'SIGNAL INFO:' LTE 'rsrq:' 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get RSRP of WWAN.
|
||||
function get_wwan_rsrp() {
|
||||
get_wwan_value 'SIGNAL INFO:' LTE 'rsrp:' 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get SNR of WWAN.
|
||||
function get_wwan_snir() {
|
||||
get_wwan_value 'SIGNAL INFO:' LTE 's/n:' 3
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get band of WWAN.
|
||||
function get_wwan_band() {
|
||||
:
|
||||
#TBD
|
||||
}
|
||||
|
||||
# Get cell ID of WWAN.
|
||||
function get_wwan_cid() {
|
||||
get_wwan_value '3GPP INFO:' 3GPP 'cell id:' 4
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get location area code of WWAN.
|
||||
function get_wwan_lac() {
|
||||
get_wwan_value '3GPP INFO:' 3GPP 'location area code:' 5
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get.tracking area code of WWAN.
|
||||
function get_wwan_tac() {
|
||||
get_wwan_value '3GPP INFO:' 3GPP 'tracking area code:' 5
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get list of available WWAN networks on the modem ID.
|
||||
# get_wwan_environment <modemid>
|
||||
function get_wwan_environment() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_wwan_environment <modemid>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
echo "MMC,MNC,Name,Tech,Status"
|
||||
mmcli -m "$1" --3gpp-scan --timeout=60 |
|
||||
sed -n 's/.*\([0-9]\{3\}\)\([0-9]\{2\}\) - \(.*\) (\(.*\), \(.*\))/\1,\2,\3,\4,\5/p'
|
||||
return $?
|
||||
}
|
||||
|
899
linux/sindan_func2.sh
Executable file
899
linux/sindan_func2.sh
Executable file
@ -0,0 +1,899 @@
|
||||
#!/bin/bash
|
||||
# sindan_func2.sh
|
||||
|
||||
## Interface Layer functions
|
||||
|
||||
# Get IPv4 configuration on the interface.
|
||||
# get_v4ifconf <ifname> <iftype>
|
||||
function get_v4ifconf() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_v4ifconf <ifname> <iftype>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if [ -f /etc/dhcpcd.conf ]; then
|
||||
if grep "^interface $1" /etc/dhcpcd.conf > /dev/null 2>&1; then
|
||||
if grep "^static ip_address" /etc/dhcpcd.conf > /dev/null 2>&1; then
|
||||
echo 'manual'
|
||||
else
|
||||
echo 'dhcp'
|
||||
fi
|
||||
fi
|
||||
elif [ -f /etc/network/interfaces ]; then
|
||||
grep "^iface $1 inet" /etc/network/interfaces |
|
||||
awk '{print $4}'
|
||||
elif which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
local wwan_dev; local conpath
|
||||
if [ "$2" = "WWAN" ]; then
|
||||
wwan_dev=$(get_wwan_port "$1")
|
||||
conpath=$(nmcli -g general.con-path device show "$wwan_dev")
|
||||
else
|
||||
conpath=$(nmcli -g general.con-path device show "$1")
|
||||
fi
|
||||
nmcli -g ipv4.method connection show "$conpath"
|
||||
else ## netplan
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 address on the interface.
|
||||
# get_v4addr <ifname>
|
||||
function get_v4addr() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_v4addr <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
ip -4 addr show "$1" |
|
||||
sed -n 's/^.*inet \([0-9.]*\)\/.*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get netmask of network on the interface.
|
||||
# get_netmask <ifname>
|
||||
function get_netmask() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_netmask <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local plen; local dec
|
||||
plen=$(ip -4 addr show "$1" |
|
||||
sed -n 's/^.*inet [0-9.]*\/\([0-9]*\) .*$/\1/p')
|
||||
dec=$(( 0xFFFFFFFF ^ ((2 ** (32 - plen)) - 1) ))
|
||||
echo "$(( dec >> 24 )).$(( (dec >> 16) & 0xFF ))." \
|
||||
"$(( (dec >> 8) & 0xFF )).$(( dec & 0xFF ))" |
|
||||
sed 's/ //g'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check IPv4 automatic address processing on the interface.
|
||||
# check_v4autoconf <ifname> <v4ifconf>
|
||||
function check_v4autoconf() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: check_v4autoconf <ifname> <v4ifconf>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if [ "$2" = "dhcp" ] || [ "$2" = "auto" ]; then
|
||||
local v4addr; local dhcp_data=""; local dhcpv4addr; local cmp
|
||||
local conpath
|
||||
v4addr=$(get_v4addr "$1")
|
||||
if which dhcpcd > /dev/null 2>&1; then
|
||||
dhcp_data=$(dhcpcd -4 -U "$1" | sed "s/'//g")
|
||||
elif [ -f /var/lib/dhcp/dhclient."$1".leases ]; then
|
||||
dhcp_data=$(sed 's/"//g' /var/lib/dhcp/dhclient."$1".leases)
|
||||
elif which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
conpath=$(nmcli -g general.con-path device show $1)
|
||||
dhcp_data=$(nmcli -g dhcp4 connection show $conpath)
|
||||
else
|
||||
dhcp_data='TBD'
|
||||
fi
|
||||
echo "$dhcp_data"
|
||||
|
||||
# simple comparision
|
||||
if which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
dhcpv4addr=$(echo "$dhcp_data" |
|
||||
sed -n 's/^.*ip_address = \([0-9.]*\)/\1/p')
|
||||
else
|
||||
dhcpv4addr=$(echo "$dhcp_data" |
|
||||
sed -n 's/^ip_address=\([0-9.]*\)/\1/p')
|
||||
fi
|
||||
echo "v4addr=$v4addr, dhcpv4addr=$dhcpv4addr"
|
||||
if [ -z "$dhcpv4addr" ] || [ -z "$v4addr" ]; then
|
||||
return 1
|
||||
fi
|
||||
cmp=$(compare_v4addr "$dhcpv4addr" "$v4addr")
|
||||
if [ "$cmp" = "same" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
echo "v4conf is $2"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Get IPv4 gateways on the interface.
|
||||
# get_v4routers <ifname>
|
||||
function get_v4routers() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_v4routers <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
ip -4 route show dev "$1" |
|
||||
sed -n 's/^default via \([0-9.]*\).*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 name servers using on the system.
|
||||
function get_v4nameservers() {
|
||||
local resolvconf
|
||||
if grep 127.0.0.53 /etc/resolv.conf > /dev/null 2>&1; then
|
||||
resolvconf="/run/systemd/resolve/resolv.conf"
|
||||
else
|
||||
resolvconf="/etc/resolv.conf"
|
||||
fi
|
||||
sed -n 's/^nameserver \([0-9.]*\)$/\1/p' "$resolvconf" |
|
||||
awk -v ORS=',' '1; END {printf "\n"}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Convert the IPv4 address to decimal value.
|
||||
# ip2decimal <v4addr>
|
||||
function ip2decimal() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: ip2decimal <v4addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local o=()
|
||||
o=($(echo "$1" | sed 's/\./ /g'))
|
||||
echo $(( (o[0] << 24) | (o[1] << 16) | (o[2] << 8) | o[3] ))
|
||||
}
|
||||
|
||||
# Compare the IPv4 addresses.
|
||||
# compare_v4addr <v4addr1> <v4addr2>
|
||||
function compare_v4addr() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: compare_v4addr <v4addr1> <v4addr2>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local addr1; local addr2
|
||||
addr1=$(ip2decimal "$1")
|
||||
addr2=$(ip2decimal "$2")
|
||||
if [ "$addr1" = "$addr2" ]; then
|
||||
echo 'same'
|
||||
else
|
||||
echo 'diff'
|
||||
fi
|
||||
}
|
||||
|
||||
# Get type of the IPv4 address.
|
||||
# check_v4addr <v4addr>
|
||||
function check_v4addr() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: check_v4addr <v4addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if echo "$1" |
|
||||
grep -vE '^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' > /dev/null; then
|
||||
echo 'not IP address'
|
||||
return 1
|
||||
elif echo "$1" | grep '^127\.' > /dev/null; then
|
||||
echo 'loopback'
|
||||
return 0
|
||||
elif echo "$1" | grep '^169\.254' > /dev/null; then
|
||||
echo 'linklocal'
|
||||
return 0
|
||||
elif echo "$1" |
|
||||
grep -e '^10\.' -e '^172\.\(1[6-9]\|2[0-9]\|3[01]\)\.' -e '^192\.168\.' > /dev/null; then
|
||||
echo 'private'
|
||||
return 0
|
||||
else
|
||||
echo 'global'
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Get IPv6 configuration on the interface.
|
||||
# get_v6ifconf <ifname>
|
||||
function get_v6ifconf() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_v6ifconf <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local v6ifconf
|
||||
if [ -f /etc/dhcpcd.conf ]; then
|
||||
if grep "^interface $1" /etc/dhcpcd.conf > /dev/null 2>&1; then
|
||||
if grep "^static ip6_address" /etc/dhcpcd.conf > /dev/null 2>&1; then
|
||||
echo 'manual'
|
||||
else
|
||||
echo 'dhcp'
|
||||
fi
|
||||
fi
|
||||
elif [ -f /etc/network/interfaces ]; then
|
||||
v6ifconf=$(grep "$1 inet6" /etc/network/interfaces |
|
||||
awk '{print $4}')
|
||||
if [ -n "$v6ifconf" ]; then
|
||||
echo "$v6ifconf"
|
||||
else
|
||||
echo "automatic"
|
||||
fi
|
||||
elif which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
local wwan_dev; local conpath
|
||||
if [ "$2" = "WWAN" ]; then
|
||||
wwan_dev=$(get_wwan_port "$1")
|
||||
conpath=$(nmcli -g general.con-path device show "$wwan_dev")
|
||||
else
|
||||
conpath=$(nmcli -g general.con-path device show "$1")
|
||||
fi
|
||||
nmcli -g ipv6.method connection show "$conpath"
|
||||
else ## netplan
|
||||
echo 'TBD'
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 link local address on the interface.
|
||||
# get_v6lladdr <ifname>
|
||||
function get_v6lladdr() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_v6lladdr <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
ip -6 addr show "$1" scope link |
|
||||
sed -n 's/^.*inet6 \(fe80[0-9a-f:]*\)\/.*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get router advertisement (RA) informarion on the interface.
|
||||
# get_ra_info <ifname>
|
||||
function get_ra_info() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_info <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
rdisc6 -n "$1"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get source IPv6 addresses of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
function get_ra_addrs() {
|
||||
grep '^ from' |
|
||||
awk '{print $2}' |
|
||||
uniq |
|
||||
awk -F\n -v ORS=',' '{print}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get flags of RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
function get_ra_flags() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_flags <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
flags="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^Stateful address conf./) \
|
||||
&& match(line,/Yes/)) { #
|
||||
flags=flags "M" #
|
||||
} else if (match(line,/^Stateful other conf./) \
|
||||
&& match(line,/Yes/)) { #
|
||||
flags=flags "O" #
|
||||
} else if (match(line,/^Mobile home agent/) \
|
||||
&& match(line,/Yes/)) { #
|
||||
flags=flags "H" #
|
||||
} else if (match(line,/^Router preference/)) { #
|
||||
if (match(line,/low/)) { #
|
||||
flags=flags "l" #
|
||||
} else if (match(line,/medium/)) { #
|
||||
flags=flags "m" #
|
||||
} else if (match(line,/high/)) { #
|
||||
flags=flags "h" #
|
||||
} #
|
||||
} else if (match(line,/^Neighbor discovery proxy/) \
|
||||
&& match(line,/Yes/)) { #
|
||||
flags=flags "P" #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
flags="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", flags #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get hop limit of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_hlim <ra_source>
|
||||
function get_ra_hlim() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_hlim <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
hops="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^Hop limit/)) { #
|
||||
split(line,h," ") #
|
||||
hops=h[4] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
hops="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", hops #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get router lifetime of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_ltime <ra_source>
|
||||
function get_ra_ltime() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_ltime <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
time="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^Router lifetime/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
time="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get reachable time of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_reach <ra_source>
|
||||
function get_ra_reach() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_reach <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
time="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^Reachable time/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
time="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get retransmit time of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_retrans <ra_source>
|
||||
function get_ra_retrans() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_retrans <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
time="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^Retransmit time/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
time="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get prefixes of the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_prefs <ra_source>
|
||||
function get_ra_prefs() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_prefs <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
prefs="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^ Prefix/)) { #
|
||||
split(line,p," ") #
|
||||
prefs=prefs ","p[3] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
prefs="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", prefs #
|
||||
}' |
|
||||
sed 's/^,//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get flags of the prefix information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_pref_flags <ra_source> <ra_pref>
|
||||
function get_ra_pref_flags() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_pref_flags <ra_source> <ra_pref>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v pref="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
flags="" #
|
||||
split(pref,p,"/") #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ On-link/) && match(line,/Yes/)) { #
|
||||
flags=flags "L" #
|
||||
} else if (match(line,/^ Autonomous address conf./) \
|
||||
&& match(line,/Yes/)) { #
|
||||
flags=flags "A" #
|
||||
} else if (match(line,/^ Pref. time/)) { #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Prefix/) && line ~ p[1]) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
flags="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", flags #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get valid lifetime of the prefix information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_pref_vltime <ra_source> <ra_pref>
|
||||
function get_ra_pref_vltime() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_pref_vltime <ra_source> <ra_pref>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v pref="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
time="" #
|
||||
split(pref,p,"/") #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ Valid time/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Prefix/) && line ~ p[1]) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
flags="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get preferred lifetime of the prefix information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_pref_pltime <ra_source> <ra_pref>
|
||||
function get_ra_pref_pltime() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_pref_pltime <ra_source> <ra_pref>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v pref="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
time="" #
|
||||
split(pref,p,"/") #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ Pref. time/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Prefix/) && line ~ p[1]) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
flags="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get route information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_routes <ra_source>
|
||||
function get_ra_routes() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_routes <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
routes="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^ Route/)) { #
|
||||
split(line,r," ") #
|
||||
routes=routes ","r[3] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
routes="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", routes #
|
||||
}' |
|
||||
sed 's/^,//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get route preference of the route information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_route_flag <ra_source> <ra_route>
|
||||
function get_ra_route_flag() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_route_flag <ra_source> <ra_route>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v route="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
flag="" #
|
||||
split(route,r,"/") #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ Route preference/)) { #
|
||||
split(line,p," ") #
|
||||
flag=p[4] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Route/) && line ~ r[1]) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
flag="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", flag #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get route lifetime of the route information in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_route_ltime <ra_source> <ra_route>
|
||||
function get_ra_route_ltime() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_route_ltime <ra_source> <ra_route>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v route="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
time="" #
|
||||
split(route,r,"/") #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ Route lifetime/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[4] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Route/) && line ~ r[1]) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
time="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get recursive DNS servers in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_rdnsses <ra_source>
|
||||
function get_ra_rdnsses() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_ra_rdnsses <ra_source>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" 'BEGIN { #
|
||||
rdnsses="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (match(line,/^ Recursive DNS server/)) { #
|
||||
split(line,r," ") #
|
||||
rdnsses=rdnsses ","r[5] #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
rdnsses="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", rdnsses #
|
||||
}' |
|
||||
sed 's/^,//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get RDNSS lifetime in the RA.
|
||||
# require get_ra_info() data from STDIN.
|
||||
# get_ra_rdnss_ltime <ra_source> <ra_route>
|
||||
function get_ra_rdnss_ltime() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_ra_rdnss_ltime <ra_source> <ra_route>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
awk -v src="$1" -v rdnss="$2" 'BEGIN { #
|
||||
find=0 #
|
||||
time="" #
|
||||
} { #
|
||||
while (getline line) { #
|
||||
if (find==1) { #
|
||||
if (match(line,/^ DNS server lifetime/)) { #
|
||||
split(line,t," ") #
|
||||
time=t[5] #
|
||||
find=0 #
|
||||
} #
|
||||
} else if (match(line,/^ Recursive DNS server/) \
|
||||
&& line ~ rdnss) { #
|
||||
find=1 #
|
||||
} else if (match(line,/^ from.*/)) { #
|
||||
if (line ~ src) { #
|
||||
exit #
|
||||
} else { #
|
||||
time="" #
|
||||
} #
|
||||
} #
|
||||
} #
|
||||
} END { #
|
||||
printf "%s", time #
|
||||
}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check IPv6 automatic address processing per the RA on the interface.
|
||||
# check_v6autoconf <ifname> <v6ifconf> \
|
||||
# <ra_flags> <ra_prefix> <ra_prefix_flags>
|
||||
function check_v6autoconf() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: check_v6autoconf <ifname> <v6ifconf> <ra_flags>" \
|
||||
"<ra_prefix> <ra_prefix_flags>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local result=1
|
||||
if [ "$2" = "automatic" ] || [ "$2" = "auto" ]; then
|
||||
local o_flag; local m_flag; local a_flag; local v6addrs
|
||||
local dhcp_data=""
|
||||
o_flag=$(echo "$3" | grep O)
|
||||
m_flag=$(echo "$3" | grep M)
|
||||
v6addrs=$(get_v6addrs "$1" "$4")
|
||||
a_flag=$(echo "$5" | grep A)
|
||||
#
|
||||
rdisc6 -n "$1"
|
||||
if [ -n "$a_flag" ] && [ -n "$v6addrs" ]; then
|
||||
result=0
|
||||
fi
|
||||
if [ -n "$o_flag" ] || [ -n "$m_flag" ]; then
|
||||
local conpath
|
||||
if which dhcpcd > /dev/null 2>&1; then
|
||||
dhcp_data=$(dhcpcd -6 -U "$1" | sed "s/'//g")
|
||||
elif [ -f /var/lib/dhcp/dhclient."$1".leases ]; then
|
||||
dhcp_data=$(sed 's/"//g' /var/lib/dhcp/dhclient."$1".leases)
|
||||
elif which nmcli > /dev/null 2>&1 &&
|
||||
[ "$(nmcli networking)" = "enabled" ]; then
|
||||
conpath=$(nmcli -g general.con-path device show "$1")
|
||||
dhcp_data=$(nmcli -g dhcp6 connection show "$conpath")
|
||||
else
|
||||
dhcp_data='TBD'
|
||||
fi
|
||||
echo "$dhcp_data"
|
||||
fi
|
||||
if [ -n "$m_flag" ]; then
|
||||
result=$(( result + 2 ))
|
||||
for addr in $(echo "$v6addrs" | sed 's/,/ /g'); do
|
||||
# simple comparision
|
||||
if echo "$dhcp_data" |
|
||||
grep -e "dhcp6_ia_na1_ia_addr1=${addr}" \
|
||||
-e "ip_address = ${addr}" > /dev/null 2>&1; then
|
||||
result=0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
return $result
|
||||
fi
|
||||
echo "v6conf is $2"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Get IPv6 addresses configured by the RA on the interface.
|
||||
# get_v6addrs <ifname> <ra_prefix>
|
||||
function get_v6addrs() {
|
||||
if [ $# -le 1 ]; then
|
||||
# ra_prefix can be omitted in case of manual configuration.
|
||||
echo "ERROR: get_v6addrs <ifname> <ra_prefix>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local pref
|
||||
pref=$(echo "$2" | sed -n 's/^\([0-9a-f:]*\):\/.*$/\1/p')
|
||||
ip -6 addr show "$1" scope global |
|
||||
sed -n "s/^.*inet6 \(${pref}[0-9a-f:]*\)\/.*$/\1/p" |
|
||||
awk -F\n -v ORS=',' '{print}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 prefix length configured by the RA.
|
||||
# get_prefixlen <ra_prefix>
|
||||
function get_prefixlen() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_prefixlen <ra_prefix>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
echo "$1" |
|
||||
awk -F/ '{print $2}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 prefix length of the IPv6 address on the interface.
|
||||
# get_prefixlen_from_ifinfo <ifname> <v6addr>
|
||||
function get_prefixlen_from_ifinfo() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: get_prefixlen_from_ifinfo <ifname> <v6addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
ip -6 addr show "$1" scope global |
|
||||
grep "$2" |
|
||||
sed -n "s/^.*inet6 [0-9a-f:]*\/\([0-9]*\).*$/\1/p"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 gateways on the interface.
|
||||
# get_v6routers <ifname>
|
||||
function get_v6routers() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_v6routers <ifname>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
ip -6 route show dev "$1" |
|
||||
sed -n "s/^default via \([0-9a-f:]*\).*$/\1/p" |
|
||||
sed "/fe80/s/$/%$1/g" |
|
||||
uniq |
|
||||
awk -v ORS=',' '1; END{printf "\n"}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 name servers using on the system.
|
||||
function get_v6nameservers() {
|
||||
local resolvconf
|
||||
if grep 127.0.0.53 /etc/resolv.conf > /dev/null 2>&1; then
|
||||
resolvconf="/run/systemd/resolve/resolv.conf"
|
||||
else
|
||||
resolvconf="/etc/resolv.conf"
|
||||
fi
|
||||
sed -n 's/^nameserver \([0-9a-f:]*\)$/\1/p' "$resolvconf" |
|
||||
awk -v ORS=',' '1; END{printf "\n"}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get type of the IPv6 address.
|
||||
# check_v6addr <v6addr>
|
||||
function check_v6addr() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: check_v6addr <v6addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
# IPv6 address format check (TBD)
|
||||
#if [ ]; then
|
||||
#return 1
|
||||
#fi
|
||||
if echo "$1" |
|
||||
grep -e '^::1$' -e '^\(0\+:\)\{7\}0*1$' > /dev/null; then
|
||||
echo 'loopback'
|
||||
return 0
|
||||
elif echo "$1" | grep '^fe80:' > /dev/null; then
|
||||
echo 'linklocal'
|
||||
return 0
|
||||
elif echo "$1" | grep '^fec0:' > /dev/null; then
|
||||
echo 'sitelocal'
|
||||
return 0
|
||||
elif echo "$1" | grep -e '^fc00:' -e '^fd00:' > /dev/null; then
|
||||
echo 'ula'
|
||||
return 0
|
||||
else
|
||||
echo 'global'
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
78
linux/sindan_func3.sh
Executable file
78
linux/sindan_func3.sh
Executable file
@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
# sindan_func3.sh
|
||||
|
||||
## Localnet Layer functions
|
||||
|
||||
# Do ping command to the target address.
|
||||
# do_ping <version> <target_addr>
|
||||
function do_ping() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: do_ping <version> <target_addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
case $1 in
|
||||
"4" ) ping -i 0.2 -c 10 "$2"; return $? ;;
|
||||
"6" ) ping6 -i 0.2 -c 10 "$2"; return $? ;;
|
||||
* ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Get RTT of ping command.
|
||||
# require do_ping() data from STDIN.
|
||||
function get_rtt() {
|
||||
sed -n 's/^rtt.* \([0-9\.\/]*\) .*$/\1/p' |
|
||||
sed 's/\// /g'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get paket loss rate of ping command.
|
||||
# require do_ping() data from STDIN.
|
||||
function get_loss() {
|
||||
sed -n 's/^.* \([0-9.]*\)\% packet loss.*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check the state of ping command to the target address.
|
||||
# cmdset_ping <layer> <version> <target_type> \
|
||||
# <target_addr> <count>
|
||||
function cmdset_ping() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_ping <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local count=$5
|
||||
local rtt_type=(min ave max dev)
|
||||
local result=$FAIL
|
||||
local string=" ping to $ipv $type: $target"
|
||||
local ping_result; local rtt_data; local rtt_loss
|
||||
|
||||
if ping_result=$(do_ping "$ver" "$target"); then
|
||||
result=$SUCCESS
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}alive_${type}" "$result" "$target" \
|
||||
"$ping_result" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
rtt_data=($(echo "$ping_result" | get_rtt))
|
||||
for i in 0 1 2 3; do
|
||||
write_json "$layer" "$ipv" "v${ver}rtt_${type}_${rtt_type[$i]}" \
|
||||
"$INFO" "$target" "${rtt_data[$i]}" "$count"
|
||||
done
|
||||
rtt_loss=$(echo "$ping_result" | get_loss)
|
||||
write_json "$layer" "$ipv" "v${ver}loss_${type}" "$INFO" "$target" \
|
||||
"$rtt_loss" "$count"
|
||||
string="$string\n status: ok"
|
||||
string="$string, rtt: ${rtt_data[1]} msec, loss: $rtt_loss %"
|
||||
else
|
||||
string="$string\n status: ng"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
138
linux/sindan_func4.sh
Executable file
138
linux/sindan_func4.sh
Executable file
@ -0,0 +1,138 @@
|
||||
#!/bin/bash
|
||||
# sindan_func4.sh
|
||||
|
||||
## Globalnet Layer functions
|
||||
|
||||
# Do traceroute command to the target address.
|
||||
# do_traceroute <version> <target_addr>
|
||||
function do_traceroute() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: do_traceroute <version> <target_addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
case $1 in
|
||||
"4" ) timeout -sKILL 30 traceroute -n -I -w 2 -q 1 -m 20 "$2"; return $? ;;
|
||||
"6" ) timeout -sKILL 30 traceroute6 -n -I -w 2 -q 1 -m 20 "$2"; return $? ;;
|
||||
* ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Get trace path of traceroute command.
|
||||
# require do_traceroute() data from STDIN.
|
||||
function get_tracepath() {
|
||||
grep -v traceroute |
|
||||
awk '{print $2}' |
|
||||
awk -F\n -v ORS=',' '{print}' |
|
||||
sed 's/,$//'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Do Path MTU discovery to the target address.
|
||||
# do_pmtud <version> <target_addr> <min_mtu> <src_addr> <max_mtu>
|
||||
function do_pmtud() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: do_pmtud <version> <target_addr> <min_mtu> <src_addr>" \
|
||||
"<max_mtu>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
case $1 in
|
||||
"4" ) command="ping -i 0.2 -W 1"; dfopt="-M do"; header=28 ;;
|
||||
"6" ) command="ping6 -i 0.2 -W 1"; dfopt="-M do"; header=48 ;;
|
||||
* ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
||||
esac
|
||||
if ! eval $command -c 1 $2 -I $5 > /dev/null; then
|
||||
echo 0
|
||||
return 1
|
||||
fi
|
||||
local version=$1
|
||||
local target=$2
|
||||
local min=$3
|
||||
local max=$4
|
||||
local src_addr=$5
|
||||
local mid=$(( ( min + max ) / 2 ))
|
||||
|
||||
while [ "$min" -ne "$mid" ] && [ "$max" -ne "$mid" ]; do
|
||||
if eval $command -c 1 -s $mid $dfopt $target -I $src_addr >/dev/null 2>/dev/null
|
||||
then
|
||||
min=$mid
|
||||
else
|
||||
max=$mid
|
||||
fi
|
||||
mid=$((( min + max ) / 2))
|
||||
done
|
||||
echo "$(( min + header ))"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check the state of traceroute command to the target address.
|
||||
# cmdset_trace <layer> <version> <target_type> <target_addr> <count>
|
||||
function cmdset_trace() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_trace <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local count=$5
|
||||
local result=$FAIL
|
||||
local string=" traceroute to $ipv $type: $target"
|
||||
local path_result; local path_data
|
||||
|
||||
if path_result=$(do_traceroute "$ver" "$target" | sed 's/\*/-/g'); then
|
||||
result=$SUCCESS
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}path_detail_${type}" "$INFO" \
|
||||
"$target" "$path_result" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
path_data=$(echo "$path_result" | get_tracepath)
|
||||
write_json "$layer" "$ipv" "v${ver}path_${type}" "$INFO" \
|
||||
"$target" "$path_data" "$count"
|
||||
string="$string\n path: $path_data"
|
||||
else
|
||||
string="$string\n status: ng"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check Path MTU to the target address.
|
||||
# cmdset_pmtud <layer> <version> <target_type> <target_addr> \
|
||||
# <ifmtu> <count> <src_addr>
|
||||
function cmdset_pmtud() {
|
||||
if [ $# -ne 7 ]; then
|
||||
echo "ERROR: cmdset_pmtud <layer> <version> <target_type>" \
|
||||
"<target_addr> <ifmtu> <count> <src_addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local min_mtu=56
|
||||
local max_mtu=$5
|
||||
local count=$6
|
||||
local src_addr=$7
|
||||
local string=" pmtud to $ipv server: $target, from: $src_addr"
|
||||
local pmtu_result
|
||||
|
||||
pmtu_result=$(do_pmtud "$ver" "$target" "$min_mtu" "$max_mtu" "$src_addr")
|
||||
if [ "$pmtu_result" -eq 0 ]; then
|
||||
write_json "$layer" "$ipv" "v${ver}pmtu_${type}" "$INFO" "$target" \
|
||||
"unmeasurable,$src_addr" "$count"
|
||||
string="$string\n pmtu: unmeasurable"
|
||||
else
|
||||
write_json "$layer" "$ipv" "v${ver}pmtu_${type}" "$INFO" "$target" \
|
||||
"$pmtu_result,$src_addr" "$count"
|
||||
string="$string\n pmtu: $pmtu_result byte"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
123
linux/sindan_func5.sh
Executable file
123
linux/sindan_func5.sh
Executable file
@ -0,0 +1,123 @@
|
||||
#!/bin/bash
|
||||
# sindan_func5.sh
|
||||
|
||||
## DNS Layer functions
|
||||
|
||||
# Do DNS lookup the target FQDN using the name server.
|
||||
# do_dnslookup <nameserver> <query_type> <target_fqdn>
|
||||
function do_dnslookup() {
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "ERROR: do_dnslookup <nameserver> <query_type>" \
|
||||
"<target_fqdn>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
dig @"$1" "$3" "$2" +time=1
|
||||
# Dig return codes are:
|
||||
# 0: Everything went well, including things like NXDOMAIN
|
||||
# 1: Usage error
|
||||
# 8: Couldn't open batch file
|
||||
# 9: No reply from server
|
||||
# 10: Internal error
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get answer of the DNS request.
|
||||
# require do_dnslookup() data from STDIN.
|
||||
# get_dnsans <query_type>
|
||||
function get_dnsans() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_dnsans <query_type>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
grep -v -e '^$' -e '^;' |
|
||||
grep " $1" -m 1 |
|
||||
awk '{print $5}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get TTL of the DNS record.
|
||||
# require do_dnslookup() data from STDIN.
|
||||
# get_dnsttl <query_type>
|
||||
function get_dnsttl() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: get_dnsttl <query_type>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
grep -v -e '^$' -e '^;' |
|
||||
grep " $1" -m 1 |
|
||||
awk '{print $2}'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get query time of the DNS request.
|
||||
# require do_dnslookup() data from STDIN.
|
||||
function get_dnsrtt() {
|
||||
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check if the DNS64 function is working on the name server.
|
||||
# check_dns64 <nameserver>
|
||||
function check_dns64() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: check_dns64 <nameserver>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local dns_ans
|
||||
dns_ans=$(do_dnslookup "$1" AAAA ipv4only.arpa |
|
||||
get_dnsans AAAA)
|
||||
if [ -n "$dns_ans" ]; then
|
||||
echo 'yes'
|
||||
else
|
||||
echo 'no'
|
||||
fi
|
||||
}
|
||||
|
||||
# Check the state of DNS lookup command to the target address.
|
||||
# cmdset_dnslookup <layer> <version> <target_type> <target_addr> <count>
|
||||
function cmdset_dnslookup() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_dnslookup <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local dns_result=""
|
||||
local string=" dns lookup for $type record by $ipv nameserver: $target"
|
||||
local dns_ans; local dns_ttl; local dns_rtt
|
||||
|
||||
for fqdn in $(echo "$FQDNS" | sed 's/,/ /g'); do
|
||||
local result=$FAIL
|
||||
string="$string\n resolve server: $fqdn"
|
||||
if dns_result=$(do_dnslookup "$target" "$type" "$fqdn"); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}dnsqry_${type}_${fqdn}" \
|
||||
"$result" "$target" "$dns_result" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
dns_ans=$(echo "$dns_result" | get_dnsans "$type")
|
||||
write_json "$layer" "$ipv" "v${ver}dnsans_${type}_${fqdn}" \
|
||||
"$INFO" "$target" "$dns_ans" "$count"
|
||||
dns_ttl=$(echo "$dns_result" | get_dnsttl "$type")
|
||||
write_json "$layer" "$ipv" "v${ver}dnsttl_${type}_${fqdn}" \
|
||||
"$INFO" "$target" "$dns_ttl" "$count"
|
||||
dns_rtt=$(echo "$dns_result" | get_dnsrtt)
|
||||
write_json "$layer" "$ipv" "v${ver}dnsrtt_${type}_${fqdn}" \
|
||||
"$INFO" "$target" "$dns_rtt" "$count"
|
||||
string="$string\n status: ok, result(ttl): $dns_ans($dns_ttl s),"
|
||||
string="$string query time: $dns_rtt ms"
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
done
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
348
linux/sindan_func6.sh
Executable file
348
linux/sindan_func6.sh
Executable file
@ -0,0 +1,348 @@
|
||||
#!/bin/bash
|
||||
# sindan_func6.sh
|
||||
|
||||
## Application Layer functions
|
||||
|
||||
# Do curl command to the target URL.
|
||||
# do_curl <version> <target_url>
|
||||
function do_curl() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: do_curl <version> <target_url>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
if [ "$1" != 4 ] && [ "$1" != 6 ]; then
|
||||
echo "ERROR: <version> must be 4 or 6." 1>&2
|
||||
return 9
|
||||
fi
|
||||
curl -"$1" -L --connect-timeout 5 --write-out %{http_code} --silent \
|
||||
--output /dev/null "$2"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check HTTP process to the target URL.
|
||||
# cmdset_http <layer> <version> <target_type> <target_url> <count>
|
||||
function cmdset_http() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_http <layer> <version> <target_type>" \
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local count=$5
|
||||
local result=$FAIL
|
||||
local string=" curl to extarnal server: $target by $ipv"
|
||||
local http_ans
|
||||
|
||||
if http_ans=$(do_curl "$ver" "$target"); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}http_${type}" "$result" "$target" \
|
||||
"$http_ans" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
string="$string\n status: ok, http status code: $http_ans"
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
# Do ssh-keyscan to the target server.
|
||||
# do_sshkeyscan <version> <target> <key_type>
|
||||
function do_sshkeyscan() {
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "ERROR: do_sshkeyscan <version> <target> <key_type>." 1>&2 \
|
||||
return 1
|
||||
fi
|
||||
ssh-keyscan -"$1" -T 5 -t "$3" "$2" 2>/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check the state of the ssh key on the target server.
|
||||
# cmdset_ssh <layer> <version> <target_type> <target_str> <count>
|
||||
function cmdset_ssh() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_ssh <layer> <version> <target_type>" \
|
||||
"<target_str> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target; local key_type
|
||||
target=$(echo "$4" | awk -F_ '{print $1}')
|
||||
key_type=$(echo "$4" | awk -F_ '{print $2}')
|
||||
local count=$5
|
||||
local result=$FAIL
|
||||
local string=" sshkeyscan to extarnal server: $target by $ipv"
|
||||
local ssh_ans
|
||||
|
||||
if ssh_ans=$(do_sshkeyscan "$ver" "$target" "$key_type"); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}ssh_${type}" "$result" "$target" \
|
||||
"$ssh_ans" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
string="$string\n status: ok"
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
# Do port scan to the target server.
|
||||
# do_portscan <verson> <target> <port>
|
||||
function do_portscan() {
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "ERROR: do_portscan <verson> <target> <port>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
case $1 in
|
||||
"4" ) nc -zv4 -w1 "$2" "$3" 2>&1 ; return $? ;;
|
||||
"6" ) nc -zv6 -w1 "$2" "$3" 2>&1 ; return $? ;;
|
||||
"*" ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check the state of the port scan result to the target server.
|
||||
# cmdset_portscan <layer> <version> <target_type> <target_addr> \
|
||||
# <target_port> <count>
|
||||
function cmdset_portscan() {
|
||||
if [ $# -ne 6 ]; then
|
||||
echo "ERROR: cmdset_portscan <layer> <version> <target_type>" \
|
||||
"<target_addr> <target_port> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local ipv="IPv${ver}"
|
||||
local type=$3
|
||||
local target=$4
|
||||
local port=$5
|
||||
local count=$6
|
||||
local result=$FAIL
|
||||
local string=" portscan to extarnal server: $target:$port by $ipv"
|
||||
local ps_ans
|
||||
|
||||
if ps_ans=$(do_portscan "$ver" "$target" "$port"); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
write_json "$layer" "$ipv" "v${ver}portscan_${port}" "$result" \
|
||||
"$target" "$ps_ans" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
string="$string\n status: ok"
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
# Do measure speed index to the target URL.
|
||||
# do_speedindex <target_url>
|
||||
function do_speedindex() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: do_speedindex <target_url>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
tracejson=trace-json/$(echo "$1" | sed 's/[.:/]/_/g').json
|
||||
node speedindex.js "$1" "$SI_TIMEOUT" ${tracejson}
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check the state of the speed index to the target URL.
|
||||
# cmdset_speedindex <layer> <version> <target_type> \
|
||||
# <target_url> <count>
|
||||
function cmdset_speedindex() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_speedindex <layer> <version> <target_type>" \
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local type=$3
|
||||
local target=$4
|
||||
local count=$5
|
||||
local result=$FAIL
|
||||
local string=" speedindex to extarnal server: $target by $ver (timeout: $SI_TIMEOUT)"
|
||||
local speedindex_ans
|
||||
|
||||
if speedindex_ans=$(do_speedindex ${target}); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
write_json "$layer" "$ver" speedindex "$result" "$target" \
|
||||
"$speedindex_ans" "$count"
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
string="$string\n status: ok, speed index value: $speedindex_ans"
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
# Do iNonius speedtest to the target URL.
|
||||
# do_speedtest <target_url>
|
||||
function do_speedtest() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: do_speedtest <target_url>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
node speedtest.js "$1"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 RTT from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv4_rtt() {
|
||||
sed -n 's/IPv4_RTT://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 jitter from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv4_jit() {
|
||||
sed -n 's/IPv4_JIT://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 download speed from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv4_dl() {
|
||||
sed -n 's/IPv4_DL://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv4 upload speed from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv4_ul() {
|
||||
sed -n 's/IPv4_UL://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 RTT from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv6_rtt() {
|
||||
sed -n 's/IPv6_RTT://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 jitter from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv6_jit() {
|
||||
sed -n 's/IPv6_JIT://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 download speed from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv6_dl() {
|
||||
sed -n 's/IPv6_DL://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Get IPv6 upload speed from the result of iNonius speedtest.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv6_ul() {
|
||||
sed -n 's/IPv6_UL://p'
|
||||
return $?
|
||||
}
|
||||
|
||||
# Check the state of iNonius speedtest result to the target URL.
|
||||
# cmdset_speedtest <layer> <version> <target_type> \
|
||||
# <target_url> <count>
|
||||
function cmdset_speedtest() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_speedtest <layer> <version> <target_type>" \
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
local ver=$2
|
||||
local type=$3
|
||||
local target=$4
|
||||
local count=$5
|
||||
local result=$FAIL
|
||||
local string=" speedtest to extarnal server: $target by $ver"
|
||||
local speedtest_ans
|
||||
local ipv4_rtt; local ipv4_jit; local ipv4_dl; local ipv4_ul
|
||||
local ipv6_rtt; local ipv6_jit; local ipv6_dl; local ipv6_ul
|
||||
|
||||
if speedtest_ans=$(do_speedtest "$target"); then
|
||||
result=$SUCCESS
|
||||
else
|
||||
stat=$?
|
||||
fi
|
||||
if [ "$result" = "$SUCCESS" ]; then
|
||||
string="$string\n status: ok"
|
||||
write_json "$layer" "$ver" speedtest "$result" "$target" \
|
||||
"$speedtest_ans" "$count"
|
||||
if ipv4_rtt=$(echo "$speedtest_ans" | get_speedtest_ipv4_rtt); then
|
||||
write_json "$layer" IPv4 v4speedtest_rtt "$INFO" "$target" \
|
||||
"$ipv4_rtt" "$count"
|
||||
string="$string\n IPv4 RTT: $ipv4_rtt ms"
|
||||
fi
|
||||
if ipv4_jit=$(echo "$speedtest_ans" | get_speedtest_ipv4_jit); then
|
||||
write_json "$layer" IPv4 v4speedtest_jitter "$INFO" "$target" \
|
||||
"$ipv4_jit" "$count"
|
||||
string="$string\n IPv4 Jitter: $ipv4_jit ms"
|
||||
fi
|
||||
if ipv4_dl=$(echo "$speedtest_ans" | get_speedtest_ipv4_dl); then
|
||||
write_json "$layer" IPv4 v4speedtest_download "$INFO" "$target" \
|
||||
"$ipv4_dl" "$count"
|
||||
string="$string\n IPv4 Download Speed: $ipv4_dl Mbps"
|
||||
fi
|
||||
if ipv4_ul=$(echo "$speedtest_ans" | get_speedtest_ipv4_ul); then
|
||||
write_json "$layer" IPv4 v4speedtest_upload "$INFO" "$target" \
|
||||
"$ipv4_ul" "$count"
|
||||
string="$string\n IPv4 Upload Speed: $ipv4_ul Mbps"
|
||||
fi
|
||||
if ipv6_rtt=$(echo "$speedtest_ans" | get_speedtest_ipv6_rtt); then
|
||||
write_json "$layer" IPv6 v6speedtest_rtt "$INFO" "$target" \
|
||||
"$ipv6_rtt" "$count"
|
||||
string="$string\n IPv6 RTT: $ipv6_rtt ms"
|
||||
fi
|
||||
if ipv6_jit=$(echo "$speedtest_ans" | get_speedtest_ipv6_jit); then
|
||||
write_json "$layer" IPv6 v6speedtest_jitter "$INFO" "$target" \
|
||||
"$ipv6_jit" "$count"
|
||||
string="$string\n IPv6 Jitter: $ipv6_jit ms"
|
||||
fi
|
||||
if ipv6_dl=$(echo "$speedtest_ans" | get_speedtest_ipv6_dl); then
|
||||
write_json "$layer" IPv6 v6speedtest_download "$INFO" "$target" \
|
||||
"$ipv6_dl" "$count"
|
||||
string="$string\n IPv6 Download Speed: $ipv6_dl Mbps"
|
||||
fi
|
||||
if ipv6_ul=$(echo "$speedtest_ans" | get_speedtest_ipv6_ul); then
|
||||
write_json "$layer" IPv6 v6speedtest_upload "$INFO" "$target" \
|
||||
"$ipv6_ul" "$count"
|
||||
string="$string\n IPv6 Upload Speed: $ipv6_ul Mbps"
|
||||
fi
|
||||
else
|
||||
string="$string\n status: ng ($stat)"
|
||||
fi
|
||||
if [ "$VERBOSE" = "yes" ]; then
|
||||
echo -e "$string"
|
||||
fi
|
||||
}
|
||||
|
99
linux/sindan_funcb.sh
Executable file
99
linux/sindan_funcb.sh
Executable file
@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
# sindan_funcb.sh
|
||||
|
||||
## Basic functions
|
||||
|
||||
# Generate UUID.
|
||||
function generate_uuid() {
|
||||
uuidgen
|
||||
}
|
||||
|
||||
# Generate a hash value of privacy data.
|
||||
# hash_result <type> <src>.
|
||||
function hash_result() {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "ERROR: hash_result <type> <src>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
type="$1"
|
||||
src="$2"
|
||||
case "$type" in
|
||||
"ssid"|"bssid")
|
||||
if [ "$LOCAL_NETWORK_PRIVACY" = "yes" ]; then
|
||||
echo "$(echo "$src" | $CMD_HASH | cut -d' ' -f1):SHA1"
|
||||
else
|
||||
echo "$src"
|
||||
fi
|
||||
;;
|
||||
"environment")
|
||||
# XXX do something if "$LOCAL_NETWORK_PRIVACY" = "yes".
|
||||
if [ "$LOCAL_NETWORK_PRIVACY" = "yes" ]; then
|
||||
echo 'XXX'
|
||||
else
|
||||
echo "$src"
|
||||
fi
|
||||
;;
|
||||
"mac_addr")
|
||||
if [ "$CLIENT_PRIVACY" = "yes" ]; then
|
||||
echo "$(echo "$src" | $CMD_HASH | cut -d' ' -f1):SHA1"
|
||||
else
|
||||
echo "$src"
|
||||
fi
|
||||
;;
|
||||
"v4autoconf"|"v6autoconf")
|
||||
# XXX do something if "$CLIENT_PRIVACY" = "yes".
|
||||
if [ "$CLIENT_PRIVACY" = "yes" ]; then
|
||||
echo 'XXX'
|
||||
else
|
||||
echo "$src"
|
||||
fi
|
||||
;;
|
||||
*) echo "$src" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Generate JSON data of campaign.
|
||||
# write_json_campaign <uuid> <mac_addr> <os> <network_type> <network_id>.
|
||||
function write_json_campaign() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: write_json_campaign <uuid> <mac_addr> <os>" \
|
||||
"<network_type> <network_id>." 1>&2
|
||||
echo "DEBUG(input data): $1, $2, $3, $4, $5" 1>&2
|
||||
return 1
|
||||
fi
|
||||
local mac_addr; local network_id
|
||||
mac_addr=$(hash_result mac_addr "$2")
|
||||
network_id=$(hash_result ssid "$5")
|
||||
echo "{ \"log_campaign_uuid\" : \"$1\"," \
|
||||
"\"mac_addr\" : \"$mac_addr\"," \
|
||||
"\"os\" : \"$3\"," \
|
||||
"\"network_type\" : \"$4\"," \
|
||||
"\"ssid\" : \"$network_id\"," \
|
||||
"\"version\" : \"$VERSION\"," \
|
||||
"\"occurred_at\" : \"$(date -u '+%Y-%m-%d %T')\" }" \
|
||||
> log/campaign_"$(date -u '+%s')".json
|
||||
return $?
|
||||
}
|
||||
|
||||
# Generate JSON data for measurement results.
|
||||
# write_json <layer> <group> <type> <result> <target> <detail> <count>.
|
||||
function write_json() {
|
||||
if [ $# -ne 7 ]; then
|
||||
echo "ERROR: write_json <layer> <group> <type> <result> <target>" \
|
||||
"<detail> <count>. ($4)" 1>&2
|
||||
echo "DEBUG(input data): $1, $2, $3, $4, $5, $6, $7" 1>&2
|
||||
return 1
|
||||
fi
|
||||
local detail
|
||||
detail=$(hash_result "$3" "$6")
|
||||
echo "{ \"layer\" : \"$1\"," \
|
||||
"\"log_group\" : \"$2\"," \
|
||||
"\"log_type\" : \"$3\"," \
|
||||
"\"log_campaign_uuid\" : \"$UUID\"," \
|
||||
"\"result\" : \"$4\"," \
|
||||
"\"target\" : \"$5\"," \
|
||||
"\"detail\" : \"$detail\"," \
|
||||
"\"occurred_at\" : \"$(date -u '+%Y-%m-%d %T')\" }" \
|
||||
> log/sindan_"$1"_"$3"_"$7"_"$(date -u '+%s')".json
|
||||
return $?
|
||||
}
|
Reference in New Issue
Block a user