|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
欢迎大家来到仓酷云论坛!比来一向在写一个主动检测收集内主机范例的剧本。基础功效能够完成判别主机操纵体系范例,假如是域内的主机能够猎取主机的硬件参数和功能参数,并判别是不是存在收集装备。对一个运维职员来讲常常必要尽快熟习一个生疏的收集。以是这个剧本就很便利了,假如有更好的倡议接待斧正感激!- #############################################Author:Lixiaosong#Email:lixiaosong8706@gmail.com#For:检测/24掩码收集内主机体系范例并猎取windows主机参数#Version:1.0##############################################Param([Parameter(Mandatory=$true)]$Network)$Ip=for($i=1;$i-ile255;$i+=1){"$Network.$i"}foreach($Ipaddressin$IP){#检测相干端口形态$Port3389=3389|%{echo((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_))"$true"}2>$null$Port22=22|%{echo((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_))"$true"}2>$null$Port23=23|%{echo((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_))"$true"}2>$null$Pingtest=Test-connection-ComputerName$IPaddress-quietif($Port3389-like"$true"){#办事器信息$HostSN=(GWMI-ComputerName"$Ipaddress"win32_bios).SerialNUmber$HostFirm=(GWMI-ComputerName"$Ipaddress"win32_bios).Manufacturer$HostModel=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).Model#主机信息$HostName=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).DNSHostName$DomainName=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).Domain#办事器硬件资本信息$Freemem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).FreePhysicalMemory#空余物理内存$Totalmem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).TotalVisibleMemorySize#总物理内存$cpu=((get-counter-ComputerName"$IPaddress"-counter"processor(_total)\%processortime").CounterSamples|where{$_.InstanceName-eq"_total"}).CookedValue$DiskRead="{0:0.0}KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"LogicalDisk(_total)DiskReadBytes/sec").CounterSamples|where{$_.InstanceName-eq"_total"}).CookedValue)/1KB)$DiskWrite="{0:0.0}KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"LogicalDisk(_total)DiskWriteBytes/sec").CounterSamples|where{$_.InstanceName-eq"_total"}).CookedValue)/1KB)$NetworkSent="{0:0.0}KB"-f($((Get-Counter-ComputerName"$Ipaddress"-Counter"NetworkInte***ce(*)BytesSent/sec").CounterSamples|%{$_.CookedValue}|sort|select-last1)/1KB)$NetworkReceive="{0:0.0}KB"-f($((Get-Counter-ComputerName"$IPaddress"-Counter"NetworkInte***ce(*)BytesReceived/sec").CounterSamples|%{$_.CookedValue}|sort|select-last1)/1KB)$Havecpu="{0:0.0}%"-f$cpu$Permem="{0:0.0}%"-f((($Totalmem-$Freemem)/$Totalmem)*100)$Disks=GWMI-ComputerName"$IPaddress"win32_logicaldisk|?{$_.drivetype-eq3}#猎取域内Windows主机参数Write-host"=================================================================================================================工夫:$(get-date)WINDOWS办事器:$HostName.$DomainNameIP:$($IPaddress.Padleft(2))品牌:$($HostFirm.Padleft(2))型号:$($HostModel.Padleft(2))序列号:$($HostSN.Padleft(2))CPU利用率:$($Havecpu.Padleft(8))内存利用率:$($Permem.Padleft(13))磁盘读/秒:$($DiskRead.Padleft(8))磁盘写/秒:$($DiskWrite.Padleft(13))收集发送/秒:$($NetworkSent.Padleft(8))收集吸收/秒:$($NetworkReceive.Padleft(13))盘符盘总空间余暇空间利用空间利用百分比"-ForegroundColorGreenforeach($Diskin$Disks){$Size="{0:0.0}GB"-f($Disk.Size/1GB)$FreeSpace="{0:0.0}GB"-f($Disk.FreeSpace/1GB)$Used=([int64]$Disk.size-[int64]$Disk.freespace)$SpaceUsed="{0:0.0}GB"-f($Used/1GB)$Percent="{0:0.0}%"-f($Used*100/$Disk.Size)$n=3Write-Host""$Disk.deviceid.PadRight($n)-no-ForegroundColorGreen$n=10Write-Host$Size.Padleft($n)-no-ForegroundColorGreenWrite-Host$FreeSpace.Padleft($n)-no-ForegroundColorGreenWrite-Host$SpaceUsed.Padleft($n)-no-ForegroundColorGreenWrite-Host$Percent.Padleft($n)-ForegroundColorGreen}}#判别linux主机if($port22-like"$true"){write-host"================================================================================================================办事器:$IPaddress开放端口:"22"多是一台是"linux"主机"-ForegroundColorYellow}#判别收集装备if($port23-like"$true"){Write-host"================================================================================================================办事器:$Ipaddress开放端口:"23"多是一台"收集"装备"-ForegroundColorCyan}#主机不存在if($Pingtest-like"$False"){Write-host"================================================================================================================办事器:$Ipaddress此主机不存在"-ForegroundColorRed}}
复制代码 利用***举例:
1将剧本保留至c:
2运转powershell实行PSC:>. est.ps110.7.2#只需输出收集的前三位
PSC:>. est.ps110.7.2
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们! |
|