Last active
August 29, 2015 14:12
-
-
Save ooltcloud/406ee5e21d766dcd9e2f to your computer and use it in GitHub Desktop.
連続Ping
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
Function CPing($from, $to, $timout) { | |
# タイムアウト値設定 | |
$w = [int]$timout; | |
if ($w -le 0) { | |
$w = 50; | |
} | |
# ipv4アドレス分解 | |
$f = $from -split "\." | |
$t = $to -split "\." | |
# 実行 | |
for ($i0 = [int]$f[0]; $i0 -le [int]$t[0]; $i0 += 1) { | |
for ($i1 = [int]$f[1]; $i1 -le [int]$t[1]; $i1 += 1) { | |
for ($i2 = [int]$f[2]; $i2 -le [int]$t[2]; $i2 += 1) { | |
for ($i3 = [int]$f[3]; $i3 -le [int]$t[3]; $i3 += 1) { | |
# ipv4アドレス生成 | |
$ip = "{0}.{1}.{2}.{3}" -f $i0, $i1, $i2, $i3 | |
# ping 実行 | |
$ans = ping -n 1 -w $w $ip | |
# 判定 | |
$ans | ? {$_ -match "応答|要求"} | | |
% { | |
$m = "{0,-16}: {1}" -f $ip,$_; | |
Write-Output $m; | |
} | |
} | |
} | |
} | |
} | |
} |
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
PS> CPing 192.168.0.1 192.169.0.2 5000 | |
192.168.0.1 : 192.168.0.1 からの応答: バイト数 =32 時間 <1ms TTL=128 | |
192.168.0.2 : 192.168.0.1 からの応答: 宛先ホストに到達できません。 | |
192.169.0.1 : 要求がタイムアウトしました。 | |
192.169.0.2 : 要求がタイムアウトしました。 | |
PS> CPing 192.168.0.1 193.169.1.3 | |
192.168.0.1 : 192.168.0.1 からの応答: バイト数 =32 時間 <1ms TTL=128 | |
192.168.0.2 : 要求がタイムアウトしました。 | |
192.168.0.3 : 要求がタイムアウトしました。 | |
192.168.1.1 : 要求がタイムアウトしました。 | |
192.168.1.2 : 要求がタイムアウトしました。 | |
192.168.1.3 : 要求がタイムアウトしました。 | |
192.169.0.1 : 要求がタイムアウトしました。 | |
192.169.0.2 : 要求がタイムアウトしました。 | |
192.169.0.3 : 要求がタイムアウトしました。 | |
192.169.1.1 : 要求がタイムアウトしました。 | |
192.169.1.2 : 要求がタイムアウトしました。 | |
192.169.1.3 : 要求がタイムアウトしました。 | |
193.168.0.1 : 要求がタイムアウトしました。 | |
193.168.0.2 : 要求がタイムアウトしました。 | |
193.168.0.3 : 要求がタイムアウトしました。 | |
193.168.1.1 : 要求がタイムアウトしました。 | |
193.168.1.2 : 158.64.16.18 からの応答: 宛先ホストに到達できません。 | |
193.168.1.3 : 要求がタイムアウトしました。 | |
193.169.0.1 : 193.169.0.1 からの応答: バイト数 =32 時間 =332ms TTL=242 | |
193.169.0.2 : 要求がタイムアウトしました。 | |
193.169.0.3 : 193.169.0.3 からの応答: バイト数 =32 時間 =288ms TTL=50 | |
193.169.1.1 : 要求がタイムアウトしました。 | |
193.169.1.2 : 193.169.1.2 からの応答: バイト数 =32 時間 =280ms TTL=50 | |
193.169.1.3 : 要求がタイムアウトしました。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment