- function getlist($ip){
- 1..254 | %{$global:ips+="$ip"+"."+"$_"}
- }
-
- function getipnum($ip){
- $ipnum=0
- $i=3
- $ip.split(".") | %{$ipnum+=[int]$_*[math]::pow(255,$i--)}
- $ipnum
- }
- $global:ips=@()
- $pingResponse=@()
- $j = 0
-
- getlist "192.168.1"
- getlist "192.168.2"
- getlist "192.168.4"
- getlist "192.168.6"
- getlist "192.168.8"
-
- while( $j -le $ips.length ){
- $i = $j + 507
- $j
- $i
- $pingResponse+=(test-connection -count 1 -ComputerName $ips[$j..$i] -asjob|wait-job|Receive-Job|?{$_.StatusCode -eq 0}|select Address,Response*)
- $j = $i + 1
- remove-job *
- }
- $pingResponse | sort @{Expression={getipnum $_.Address}}
复制代码 http://hi.baidu.com/shrekzz/item/5a624713ed7a5ce09813d689 |