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
|
||||
# version 3.0.0
|
||||
# version 3
|
||||
|
||||
# PID file
|
||||
readonly PIDFILE=/tmp/sindan.pid
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# sindan.sh
|
||||
# version 3.0.1
|
||||
# version 3
|
||||
VERSION="3.0.1"
|
||||
|
||||
# read configuration file
|
||||
|
@ -31,8 +31,8 @@ function get_tracepath() {
|
||||
# do_pmtud <version> <target_addr> <min_mtu> <max_mtu> <src_addr>
|
||||
function do_pmtud() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: do_pmtud <version> <target_addr> <min_mtu> <src_addr>" \
|
||||
"<max_mtu>." 1>&2
|
||||
echo "ERROR: do_pmtud <version> <target_addr> <min_mtu> <max_mtu>" \
|
||||
"<src_addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
case $1 in
|
||||
|
@ -51,6 +51,7 @@ function get_dnsttl() {
|
||||
|
||||
# Get query time of the DNS request.
|
||||
# require do_dnslookup() data from STDIN.
|
||||
# get_dnsrtt
|
||||
function get_dnsrtt() {
|
||||
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
||||
return $?
|
||||
|
@ -97,3 +97,4 @@ function write_json() {
|
||||
> log/sindan_"$1"_"$3"_"$7"_"$(date -u '+%s')".json
|
||||
return $?
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# SINDAN Configuration file
|
||||
# version 3.0.0
|
||||
# version 3
|
||||
|
||||
# PID file
|
||||
readonly PIDFILE=/tmp/sindan.pid
|
||||
@ -7,6 +7,9 @@ readonly PIDFILE=/tmp/sindan.pid
|
||||
# lock file
|
||||
readonly LOCKFILE_SENDLOG=/tmp/sendlog.isrunning
|
||||
|
||||
# airport command
|
||||
readonly CMD_AIRPORT=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
|
||||
|
||||
# result parameters
|
||||
readonly FAIL=0
|
||||
readonly SUCCESS=1
|
||||
@ -33,12 +36,8 @@ readonly EXCL_IPv6=no
|
||||
# IFTYPE: Wi-Fi, WWAN (for Cellular), Ethernet
|
||||
readonly IFTYPE=Wi-Fi
|
||||
|
||||
# set ssid
|
||||
#readonly SSID=sindan
|
||||
#readonly SSID_KEY=sindan00
|
||||
|
||||
# airport command
|
||||
readonly CMD_AIRPORT=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
|
||||
# proxy url (e.g., http://192.0.2.1:8080)
|
||||
readonly PROXY_URL=""
|
||||
|
||||
# target servers
|
||||
readonly PING_SRVS="8.8.8.8,203.178.139.60,1.1.1.1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# sindan.sh
|
||||
# version 3.0.1
|
||||
# version 3
|
||||
VERSION="3.0.1"
|
||||
|
||||
# read configuration file
|
||||
|
@ -28,7 +28,6 @@ function get_rtt() {
|
||||
# Get paket loss rate of ping command.
|
||||
# require do_ping() data from STDIN.
|
||||
function get_loss() {
|
||||
# require do_ping() data from STDIN.
|
||||
sed -n 's/^.* \([0-9.]*\)\% packet loss.*$/\1/p'
|
||||
return $?
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ function do_pmtud() {
|
||||
fi
|
||||
case $1 in
|
||||
"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 ;;
|
||||
esac
|
||||
if ! $command -c 1 $2 > /dev/null; then
|
||||
if ! eval $command -c 1 $2 -S $5 > /dev/null; then
|
||||
echo 0
|
||||
return 1
|
||||
fi
|
||||
@ -52,7 +52,7 @@ function do_pmtud() {
|
||||
local mid=$(( ( min + max ) / 2 ))
|
||||
|
||||
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
|
||||
min=$mid
|
||||
else
|
||||
@ -106,7 +106,7 @@ function cmdset_trace() {
|
||||
function cmdset_pmtud() {
|
||||
if [ $# -ne 7 ]; then
|
||||
echo "ERROR: cmdset_pmtud <layer> <version> <target_type>" \
|
||||
"<target_addr> <ifmtu> <count>." 1>&2
|
||||
"<target_addr> <ifmtu> <count> <src_addr>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
@ -114,7 +114,7 @@ function cmdset_pmtud() {
|
||||
local ipv=IPv${ver}
|
||||
local type=$3
|
||||
local target=$4
|
||||
local min_mtu=1200
|
||||
local min_mtu=56
|
||||
local max_mtu=$5
|
||||
local count=$6
|
||||
local src_addr=$7
|
||||
|
@ -12,6 +12,12 @@ function do_dnslookup() {
|
||||
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 $?
|
||||
}
|
||||
|
||||
@ -44,8 +50,8 @@ function get_dnsttl() {
|
||||
}
|
||||
|
||||
# Get query time of the DNS request.
|
||||
# get_dnsrtt
|
||||
# require do_dnslookup() data from STDIN.
|
||||
# get_dnsrtt
|
||||
function get_dnsrtt() {
|
||||
sed -n 's/^;; Query time: \([0-9]*\) msec$/\1/p'
|
||||
return $?
|
||||
@ -55,11 +61,11 @@ function get_dnsrtt() {
|
||||
# check_dns64 <nameserver>
|
||||
function check_dns64() {
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERROR: check_dns64 <target_addr>." 1>&2
|
||||
echo "ERROR: check_dns64 <nameserver>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local dns_ans
|
||||
dns_ans=$(do_dnslookup "$target" AAAA ipv4only.arpa |
|
||||
dns_ans=$(do_dnslookup "$1" AAAA ipv4only.arpa |
|
||||
get_dnsans AAAA)
|
||||
if [ -n "$dns_ans" ]; then
|
||||
echo 'yes'
|
||||
|
@ -24,7 +24,7 @@ function do_curl() {
|
||||
function cmdset_http() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_http <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
@ -105,16 +105,52 @@ function cmdset_ssh() {
|
||||
# Do port scan to the target server.
|
||||
# do_portscan <verson> <target> <port>
|
||||
function do_portscan() {
|
||||
:
|
||||
#TBD
|
||||
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() {
|
||||
:
|
||||
#TBD
|
||||
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.
|
||||
@ -126,7 +162,7 @@ function do_speedindex() {
|
||||
fi
|
||||
|
||||
tracejson=trace-json/$(echo "$1" | sed 's/[.:/]/_/g').json
|
||||
node speedindex.js "$1" ${tracejson}
|
||||
node speedindex.js "$1" "$SI_TIMEOUT" ${tracejson}
|
||||
return $?
|
||||
}
|
||||
|
||||
@ -136,7 +172,7 @@ function do_speedindex() {
|
||||
function cmdset_speedindex() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_speedindex <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
@ -145,7 +181,7 @@ function cmdset_speedindex() {
|
||||
local target=$4
|
||||
local count=$5
|
||||
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
|
||||
|
||||
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.
|
||||
# require do_speedtest() data from STDIN.
|
||||
function get_speedtest_ipv4_ul() {
|
||||
# require do_speedtest() data from STDIN.
|
||||
sed -n 's/IPv4_UL://p'
|
||||
return $?
|
||||
}
|
||||
@ -240,7 +275,7 @@ function get_speedtest_ipv6_ul() {
|
||||
function cmdset_speedtest() {
|
||||
if [ $# -ne 5 ]; then
|
||||
echo "ERROR: cmdset_speedtest <layer> <version> <target_type>" \
|
||||
"<target_addr> <count>." 1>&2
|
||||
"<target_url> <count>." 1>&2
|
||||
return 1
|
||||
fi
|
||||
local layer=$1
|
||||
|
Reference in New Issue
Block a user