校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型

PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型

熱門標(biāo)簽:使用電話機器人電銷是否違法 真人和電話機器人對話 電話智能外呼系統(tǒng)誠信合作 金融電銷公司怎么辦理外呼系統(tǒng) 什么渠道可以找外呼系統(tǒng)客戶 湖州電銷防封卡 雷霆電話機器人電話 安徽400電話辦理 信陽話務(wù)外呼系統(tǒng)怎么收費

最近一直在寫一個自動檢測網(wǎng)絡(luò)內(nèi)主機類型的腳本。基本功能可以實現(xiàn)判斷主機操作系統(tǒng)類型,如果是域內(nèi)的主機可以獲取主機的硬件參數(shù)和性能參數(shù),并判斷是否存在網(wǎng)絡(luò)設(shè)備。對一個運維人員來說往往需要盡快熟悉一個陌生的網(wǎng)絡(luò)。所以這個腳本就很方便了,如果有更好的建議歡迎指正感謝!

復(fù)制代碼 代碼如下:

############################################
#Author:Lixiaosong
#Email:lixiaosong8706@gmail.com
#For:檢測/24掩碼網(wǎng)絡(luò)內(nèi)主機系統(tǒng)類型并獲取windows主機參數(shù)
#Version:1.0
##############################################
Param(
[Parameter(Mandatory=$true)]$Network
)
$Ip=for($i= 1; $i-ile255; $i+= 1){"$Network.$i"}
foreach($Ipaddressin$IP){
#檢測相關(guān)端口狀態(tài)
$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-quiet
if($Port3389-like"$true"){
#服務(wù)器信息
$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
#服務(wù)器硬件資源信息
$Freemem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).FreePhysicalMemory#空余物理內(nèi)存
$Totalmem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).TotalVisibleMemorySize#總物理內(nèi)存
$cpu=((get-counter-ComputerName"$IPaddress"-counter"\processor(_total)\% processor time").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue
$DiskRead=" {0:0.0} KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"\LogicalDisk(_total)\Disk Read Bytes/sec").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue) / 1KB)
$DiskWrite="{0:0.0} KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"\LogicalDisk(_total)\Disk Write Bytes/sec").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue) /1KB)
$NetworkSent=" {0:0.0} KB"-f($((Get-Counter-ComputerName"$Ipaddress"-Counter"\Network Interface(*)\Bytes Sent/sec").CounterSamples|%{$_.CookedValue}|sort|select-last1) / 1KB)
$NetworkReceive=" {0:0.0} KB"-f($((Get-Counter-ComputerName"$IPaddress"-Counter"\Network Interface(*)\Bytes Received/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}
#獲取域內(nèi)Windows主機參數(shù)
Write-host"
=================================================================================================================
時間:$(get-date) WINDOWS服務(wù)器:$HostName.$DomainName IP:$($IPaddress.Padleft(2)) 品牌:$($HostFirm.Padleft(2)) 型號:$($HostModel.Padleft(2)) 序列號:$($HostSN.Padleft(2))
CPU使用率:$($Havecpu.Padleft(8)) 內(nèi)存使用率:$($Permem.Padleft(13))
磁盤讀/秒:$($DiskRead.Padleft(8)) 磁盤寫/秒:$($DiskWrite.Padleft(13))
網(wǎng)絡(luò)發(fā)送/秒:$($NetworkSent.Padleft(8)) 網(wǎng)絡(luò)接收/秒:$($NetworkReceive.Padleft(13))
盤符   盤總空間  空閑空間  使用空間  使用百分比"-ForegroundColorGreen
foreach($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=3
Write-Host"  "$Disk.deviceid.PadRight($n)-no-ForegroundColorGreen
$n=10
Write-Host$Size.Padleft($n)-no-ForegroundColorGreen
Write-Host$FreeSpace.Padleft($n)-no-ForegroundColorGreen
Write-Host$SpaceUsed.Padleft($n)-no-ForegroundColorGreen
Write-Host$Percent.Padleft($n)-ForegroundColorGreen
}
}
#判斷l(xiāng)inux主機
if($port22-like"$true"){
write-host"
================================================================================================================
服務(wù)器:$IPaddress 開放端口:"22" 可能是一臺是"linux"主機"-ForegroundColorYellow
}
#判斷網(wǎng)絡(luò)設(shè)備
if($port23-like"$true"){
Write-host"
================================================================================================================
服務(wù)器:$Ipaddress 開放端口:"23" 可能是一臺"網(wǎng)絡(luò)"設(shè)備"-ForegroundColorCyan
}
#主機不存在
if($Pingtest-like"$False"){
Write-host"
================================================================================================================
服務(wù)器:$Ipaddress 此主機不存在"-ForegroundColorRed
}
}

使用方法舉例:

1 將腳本保存至c:\
2 運行powershell 執(zhí)行PS C:\&; .\test.ps1 10.7.2 #只需輸入網(wǎng)絡(luò)的前三位

復(fù)制代碼 代碼如下:

PS C:\&; .\test.ps1 10.7.2

您可能感興趣的文章:
  • 自動化下載并檢測ftp文件備份的shell腳本
  • 用來檢測輸入的選項$1是否在PATH中的shell腳本
  • shell腳本實現(xiàn)實時檢測文件變更
  • Shell腳本實現(xiàn)檢測Cygwin最快的鏡像站點
  • VBS腳本寫的Windows硬件檢測工具分享
  • Linux Shell腳本實現(xiàn)檢測tomcat
  • Shell腳本實現(xiàn)檢測進程是否正在運行
  • 腳本批量檢測網(wǎng)站是否存活

標(biāo)簽:鶴崗 湛江 德州 岳陽 濟南 六盤水 山南 運城

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型》,本文關(guān)鍵詞  PowerShell,腳本,實現(xiàn),檢測,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型》相關(guān)的同類信息!
  • 本頁收集關(guān)于PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 阳曲县| 桃园市| 抚顺市| 托里县| 临江市| 张掖市| 栾城县| 邵东县| 巫溪县| 政和县| 黄浦区| 万全县| 萝北县| 巴中市| 茶陵县| 西贡区| 安溪县| 渝北区| 城步| 虎林市| 惠州市| 交口县| 巴青县| 宜黄县| 兖州市| 桦甸市| 屯昌县| 民县| 通城县| 吉木萨尔县| 独山县| 容城县| 盐亭县| 商水县| 哈巴河县| 枣阳市| 江山市| 合作市| 嵊泗县| 集安市| 南宫市|