Skip to content

Instantly share code, notes, and snippets.

@kmikage
Forked from kazuhito-m/test_of_ping_ip_range.sh
Last active December 18, 2022 10:41
Show Gist options
  • Save kmikage/a39e30e18aa95451d222ec514addd01c to your computer and use it in GitHub Desktop.
Save kmikage/a39e30e18aa95451d222ec514addd01c to your computer and use it in GitHub Desktop.
同一ネットワーク内で応答のあるIPをシュッと調べる
#!/bin/bash
IP_HEAD='192.168.1.'
IP_START=1
IP_END=254
function hittest_ip() {
i=${1}
hittest_ip=${IP_HEAD}${i}
ping -c 1 -w 1 ${hittest_ip} > /dev/null
if [ ${?} -eq 0 ]; then
echo "応答のあったIP:${hittest_ip}"
fi
}
for i in $(seq ${IP_START} ${IP_END}); do
hittest_ip ${i} &
done
wait
exit 0
@kmikage
Copy link
Author

kmikage commented Feb 20, 2022

update

  • pingのtimeoutを、1秒に指定
  • 子プロセスの終了を待って、戻り値0で終了

fpingでもいいのかも知れないけど、aptなりyumが使えない環境だと、こっちの方が素直な気がしたので。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment