标题: [转载代码] PowerShell扫描网段IP [打印本页]
作者: DAIC 时间: 2013-9-16 21:53 标题: PowerShell扫描网段IP
- 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
作者: hzcxdgioa 时间: 2013-11-30 08:06
支持楼主的帖子。!!!!!!!!!!!
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |