mirror of
https://github.com/mii443/sindan-client.git
synced 2025-08-22 16:25:41 +00:00
Minimized code differences between macos and linux versions.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
# SINDAN Configuration file
|
# SINDAN Configuration file
|
||||||
# version 3.0.0
|
# version 3
|
||||||
|
|
||||||
# PID file
|
# PID file
|
||||||
readonly PIDFILE=/tmp/sindan.pid
|
readonly PIDFILE=/tmp/sindan.pid
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# sindan.sh
|
# sindan.sh
|
||||||
# version 3.0.1
|
# version 3
|
||||||
VERSION="3.0.1"
|
VERSION="3.0.1"
|
||||||
|
|
||||||
# read configuration file
|
# read configuration file
|
||||||
|
@ -31,8 +31,8 @@ function get_tracepath() {
|
|||||||
# do_pmtud <version> <target_addr> <min_mtu> <max_mtu> <src_addr>
|
# do_pmtud <version> <target_addr> <min_mtu> <max_mtu> <src_addr>
|
||||||
function do_pmtud() {
|
function do_pmtud() {
|
||||||
if [ $# -ne 5 ]; then
|
if [ $# -ne 5 ]; then
|
||||||
echo "ERROR: do_pmtud <version> <target_addr> <min_mtu> <src_addr>" \
|
echo "ERROR: do_pmtud <version> <target_addr> <min_mtu> <max_mtu>" \
|
||||||
"<max_mtu>." 1>&2
|
"<src_addr>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
case $1 in
|
case $1 in
|
||||||
|
@ -51,6 +51,7 @@ function get_dnsttl() {
|
|||||||
|
|
||||||
# Get query time of the DNS request.
|
# Get query time of the DNS request.
|
||||||
# require do_dnslookup() data from STDIN.
|
# require do_dnslookup() data from STDIN.
|
||||||
|
# get_dnsrtt
|
||||||
function get_dnsrtt() {
|
function get_dnsrtt() {
|
||||||
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
||||||
return $?
|
return $?
|
||||||
|
@ -142,7 +142,7 @@ function cmdset_portscan() {
|
|||||||
stat=$?
|
stat=$?
|
||||||
fi
|
fi
|
||||||
write_json "$layer" "$ipv" "v${ver}portscan_${port}" "$result" \
|
write_json "$layer" "$ipv" "v${ver}portscan_${port}" "$result" \
|
||||||
"$target" "$ps_ans" "$count"
|
"$target" "$ps_ans" "$count"
|
||||||
if [ "$result" = "$SUCCESS" ]; then
|
if [ "$result" = "$SUCCESS" ]; then
|
||||||
string="$string\n status: ok"
|
string="$string\n status: ok"
|
||||||
else
|
else
|
||||||
|
@ -97,3 +97,4 @@ function write_json() {
|
|||||||
> log/sindan_"$1"_"$3"_"$7"_"$(date -u '+%s')".json
|
> log/sindan_"$1"_"$3"_"$7"_"$(date -u '+%s')".json
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# SINDAN Configuration file
|
# SINDAN Configuration file
|
||||||
# version 3.0.0
|
# version 3
|
||||||
|
|
||||||
# PID file
|
# PID file
|
||||||
readonly PIDFILE=/tmp/sindan.pid
|
readonly PIDFILE=/tmp/sindan.pid
|
||||||
@ -7,6 +7,9 @@ readonly PIDFILE=/tmp/sindan.pid
|
|||||||
# lock file
|
# lock file
|
||||||
readonly LOCKFILE_SENDLOG=/tmp/sendlog.isrunning
|
readonly LOCKFILE_SENDLOG=/tmp/sendlog.isrunning
|
||||||
|
|
||||||
|
# airport command
|
||||||
|
readonly CMD_AIRPORT=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
|
||||||
|
|
||||||
# result parameters
|
# result parameters
|
||||||
readonly FAIL=0
|
readonly FAIL=0
|
||||||
readonly SUCCESS=1
|
readonly SUCCESS=1
|
||||||
@ -33,12 +36,8 @@ readonly EXCL_IPv6=no
|
|||||||
# IFTYPE: Wi-Fi, WWAN (for Cellular), Ethernet
|
# IFTYPE: Wi-Fi, WWAN (for Cellular), Ethernet
|
||||||
readonly IFTYPE=Wi-Fi
|
readonly IFTYPE=Wi-Fi
|
||||||
|
|
||||||
# set ssid
|
# proxy url (e.g., http://192.0.2.1:8080)
|
||||||
#readonly SSID=sindan
|
readonly PROXY_URL=""
|
||||||
#readonly SSID_KEY=sindan00
|
|
||||||
|
|
||||||
# airport command
|
|
||||||
readonly CMD_AIRPORT=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
|
|
||||||
|
|
||||||
# target servers
|
# target servers
|
||||||
readonly PING_SRVS="8.8.8.8,203.178.139.60,1.1.1.1"
|
readonly PING_SRVS="8.8.8.8,203.178.139.60,1.1.1.1"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# sindan.sh
|
# sindan.sh
|
||||||
# version 3.0.1
|
# version 3
|
||||||
VERSION="3.0.1"
|
VERSION="3.0.1"
|
||||||
|
|
||||||
# read configuration file
|
# read configuration file
|
||||||
|
@ -28,7 +28,6 @@ function get_rtt() {
|
|||||||
# Get paket loss rate of ping command.
|
# Get paket loss rate of ping command.
|
||||||
# require do_ping() data from STDIN.
|
# require do_ping() data from STDIN.
|
||||||
function get_loss() {
|
function get_loss() {
|
||||||
# require do_ping() data from STDIN.
|
|
||||||
sed -n 's/^.* \([0-9.]*\)\% packet loss.*$/\1/p'
|
sed -n 's/^.* \([0-9.]*\)\% packet loss.*$/\1/p'
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ function do_pmtud() {
|
|||||||
fi
|
fi
|
||||||
case $1 in
|
case $1 in
|
||||||
"4" ) command="ping -t 1"; dfopt="-D"; header=28 ;;
|
"4" ) command="ping -t 1"; dfopt="-D"; header=28 ;;
|
||||||
"6" ) command="gtimeout 3 ping6"; dfopt=""; header=48 ;;
|
"6" ) command="gtimeout -sKILL 3 ping6"; dfopt=""; header=48 ;;
|
||||||
* ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
* ) echo "ERROR: <version> must be 4 or 6." 1>&2; return 9 ;;
|
||||||
esac
|
esac
|
||||||
if ! $command -c 1 $2 > /dev/null; then
|
if ! eval $command -c 1 $2 -S $5 > /dev/null; then
|
||||||
echo 0
|
echo 0
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -52,7 +52,7 @@ function do_pmtud() {
|
|||||||
local mid=$(( ( min + max ) / 2 ))
|
local mid=$(( ( min + max ) / 2 ))
|
||||||
|
|
||||||
while [ "$min" -ne "$mid" ] && [ "$max" -ne "$mid" ]; do
|
while [ "$min" -ne "$mid" ] && [ "$max" -ne "$mid" ]; do
|
||||||
if eval "$command -c 1 -s $mid $dfopt $target -S $src_addr >/dev/null 2>/dev/null"
|
if eval $command -c 1 -s $mid $dfopt $target -S $src_addr >/dev/null 2>/dev/null
|
||||||
then
|
then
|
||||||
min=$mid
|
min=$mid
|
||||||
else
|
else
|
||||||
@ -106,7 +106,7 @@ function cmdset_trace() {
|
|||||||
function cmdset_pmtud() {
|
function cmdset_pmtud() {
|
||||||
if [ $# -ne 7 ]; then
|
if [ $# -ne 7 ]; then
|
||||||
echo "ERROR: cmdset_pmtud <layer> <version> <target_type>" \
|
echo "ERROR: cmdset_pmtud <layer> <version> <target_type>" \
|
||||||
"<target_addr> <ifmtu> <count>." 1>&2
|
"<target_addr> <ifmtu> <count> <src_addr>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local layer=$1
|
local layer=$1
|
||||||
@ -114,7 +114,7 @@ function cmdset_pmtud() {
|
|||||||
local ipv=IPv${ver}
|
local ipv=IPv${ver}
|
||||||
local type=$3
|
local type=$3
|
||||||
local target=$4
|
local target=$4
|
||||||
local min_mtu=1200
|
local min_mtu=56
|
||||||
local max_mtu=$5
|
local max_mtu=$5
|
||||||
local count=$6
|
local count=$6
|
||||||
local src_addr=$7
|
local src_addr=$7
|
||||||
|
@ -12,6 +12,12 @@ function do_dnslookup() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
dig @"$1" "$3" "$2" +time=1
|
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 $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +50,8 @@ function get_dnsttl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Get query time of the DNS request.
|
# Get query time of the DNS request.
|
||||||
# get_dnsrtt
|
|
||||||
# require do_dnslookup() data from STDIN.
|
# require do_dnslookup() data from STDIN.
|
||||||
|
# get_dnsrtt
|
||||||
function get_dnsrtt() {
|
function get_dnsrtt() {
|
||||||
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
||||||
return $?
|
return $?
|
||||||
@ -55,11 +61,11 @@ function get_dnsrtt() {
|
|||||||
# check_dns64 <nameserver>
|
# check_dns64 <nameserver>
|
||||||
function check_dns64() {
|
function check_dns64() {
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
echo "ERROR: check_dns64 <target_addr>." 1>&2
|
echo "ERROR: check_dns64 <nameserver>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local dns_ans
|
local dns_ans
|
||||||
dns_ans=$(do_dnslookup "$target" AAAA ipv4only.arpa |
|
dns_ans=$(do_dnslookup "$1" AAAA ipv4only.arpa |
|
||||||
get_dnsans AAAA)
|
get_dnsans AAAA)
|
||||||
if [ -n "$dns_ans" ]; then
|
if [ -n "$dns_ans" ]; then
|
||||||
echo 'yes'
|
echo 'yes'
|
||||||
|
@ -24,7 +24,7 @@ function do_curl() {
|
|||||||
function cmdset_http() {
|
function cmdset_http() {
|
||||||
if [ $# -ne 5 ]; then
|
if [ $# -ne 5 ]; then
|
||||||
echo "ERROR: cmdset_http <layer> <version> <target_type>" \
|
echo "ERROR: cmdset_http <layer> <version> <target_type>" \
|
||||||
"<target_addr> <count>." 1>&2
|
"<target_url> <count>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local layer=$1
|
local layer=$1
|
||||||
@ -105,16 +105,52 @@ function cmdset_ssh() {
|
|||||||
# Do port scan to the target server.
|
# Do port scan to the target server.
|
||||||
# do_portscan <verson> <target> <port>
|
# do_portscan <verson> <target> <port>
|
||||||
function do_portscan() {
|
function do_portscan() {
|
||||||
:
|
if [ $# -ne 3 ]; then
|
||||||
#TBD
|
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.
|
# Check the state of the port scan result to the target server.
|
||||||
# cmdset_portscan <layer> <version> <target_type> <target_addr> \
|
# cmdset_portscan <layer> <version> <target_type> <target_addr> \
|
||||||
# <target_port> <count>
|
# <target_port> <count>
|
||||||
function cmdset_portscan() {
|
function cmdset_portscan() {
|
||||||
:
|
if [ $# -ne 6 ]; then
|
||||||
#TBD
|
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 measure speed index to the target URL.
|
||||||
@ -126,7 +162,7 @@ function do_speedindex() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
tracejson=trace-json/$(echo "$1" | sed 's/[.:/]/_/g').json
|
tracejson=trace-json/$(echo "$1" | sed 's/[.:/]/_/g').json
|
||||||
node speedindex.js "$1" ${tracejson}
|
node speedindex.js "$1" "$SI_TIMEOUT" ${tracejson}
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +172,7 @@ function do_speedindex() {
|
|||||||
function cmdset_speedindex() {
|
function cmdset_speedindex() {
|
||||||
if [ $# -ne 5 ]; then
|
if [ $# -ne 5 ]; then
|
||||||
echo "ERROR: cmdset_speedindex <layer> <version> <target_type>" \
|
echo "ERROR: cmdset_speedindex <layer> <version> <target_type>" \
|
||||||
"<target_addr> <count>." 1>&2
|
"<target_url> <count>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local layer=$1
|
local layer=$1
|
||||||
@ -145,7 +181,7 @@ function cmdset_speedindex() {
|
|||||||
local target=$4
|
local target=$4
|
||||||
local count=$5
|
local count=$5
|
||||||
local result=$FAIL
|
local result=$FAIL
|
||||||
local string=" speedindex to extarnal server: $target by $ver"
|
local string=" speedindex to extarnal server: $target by $ver (timeout: $SI_TIMEOUT)"
|
||||||
local speedindex_ans
|
local speedindex_ans
|
||||||
|
|
||||||
if speedindex_ans=$(do_speedindex ${target}); then
|
if speedindex_ans=$(do_speedindex ${target}); then
|
||||||
@ -201,7 +237,6 @@ function get_speedtest_ipv4_dl() {
|
|||||||
# Get IPv4 upload speed from the result of iNonius speedtest.
|
# Get IPv4 upload speed from the result of iNonius speedtest.
|
||||||
# require do_speedtest() data from STDIN.
|
# require do_speedtest() data from STDIN.
|
||||||
function get_speedtest_ipv4_ul() {
|
function get_speedtest_ipv4_ul() {
|
||||||
# require do_speedtest() data from STDIN.
|
|
||||||
sed -n 's/IPv4_UL://p'
|
sed -n 's/IPv4_UL://p'
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
@ -240,7 +275,7 @@ function get_speedtest_ipv6_ul() {
|
|||||||
function cmdset_speedtest() {
|
function cmdset_speedtest() {
|
||||||
if [ $# -ne 5 ]; then
|
if [ $# -ne 5 ]; then
|
||||||
echo "ERROR: cmdset_speedtest <layer> <version> <target_type>" \
|
echo "ERROR: cmdset_speedtest <layer> <version> <target_type>" \
|
||||||
"<target_addr> <count>." 1>&2
|
"<target_url> <count>." 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local layer=$1
|
local layer=$1
|
||||||
|
Reference in New Issue
Block a user