Last active
September 28, 2018 05:01
-
-
Save kyokuheki/e5de7913ed6378f28f42572a30514dca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
progname=sping | |
usage="usage: $progname <prefix> <source> <mask> <dev> <opts>.. | |
example: | |
$progname 10.0 41 16 eth0 | |
" | |
function sping24 () { | |
local _opts="-a -t 300 -p 1 -i 1 -e -A" | |
local _dev=$1 | |
local _label=$1:spingvip | |
local _source=$2 | |
local _prefix=$3 | |
local _mask=/24 | |
shift 3 | |
echo >&2 sping: ip addr add local $_prefix.$_source$_mask dev $_dev label $_label | |
ip addr add local $_prefix.$_source$_mask dev $_dev label $_label | |
echo >&2 sping: fping $_opts -g $_prefix.0$_mask -S $_prefix.$_source $@ | |
fping $_opts -g $_prefix.0$_mask -S $_prefix.$_source $@ 2>&1 | grep -v ICMP | |
echo >&2 sping: ip addr del local $_prefix.$_source$_mask dev $_dev label $_label | |
ip addr del local $_prefix.$_source$_mask dev $_dev label $_label | |
} | |
function sping () { | |
[[ $# -lt 4 ]] && echo "$usage" && return 1 | |
local prefix=${1%%.} | |
local source=${2##.} | |
local mask=$3 | |
local dev=$4 | |
local opts="" | |
[[ $# -ge 5 ]] && opts="$opts $*" | |
export -f sping24 | |
case $mask in | |
8) | |
printf '%s\n' $prefix.{0..255}.{0..255} | |
;; | |
16) | |
printf '%s\n' $prefix.{0..255} | |
;; | |
*) | |
printf $prefix | |
;; | |
esac | /usr/bin/xargs -P16 -n1 -I {} bash -c "sping24 $dev $source {} $opts" | |
} | |
sping $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こっちでいいんじゃないの?