PowerShell实战1:Ping_Test
2009-12-11 17:04
337 查看
功能:批量测试远程主机的Ping值,以及根据TTL值来判断是否为Windows主机。
使用:在C:\IP.txt中加入需要测试的主机IP或域名,一行一个。例如:
www.google.com
www.baidu.com
www.cha123.com
www.yahoo.com
www.msn.com
源码:
function Ping_Test {
PROCESS {
$ping = $false
$results = Get-WmiObject -query `
"SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
$RT = $results.ResponseTime
$TTL = $results.ResponseTimeToLive
foreach ($result in $results) {
if ($results.StatusCode -eq 0) {
if ($TTL -ge 98 -and $TTL -le 128)
{Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL,It is a Windows host." -ForegroundColor Green }
else
{Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL, It is NOT a Windows host." -ForegroundColor Blue}
}
else {
Write-Host "`n$_ Ping failed!" -ForegroundColor Red
}
}
}
}
cls
Get-Content c:\IP.txt | Ping_Test
结果:
使用:在C:\IP.txt中加入需要测试的主机IP或域名,一行一个。例如:
www.google.com
www.baidu.com
www.cha123.com
www.yahoo.com
www.msn.com
源码:
function Ping_Test {
PROCESS {
$ping = $false
$results = Get-WmiObject -query `
"SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
$RT = $results.ResponseTime
$TTL = $results.ResponseTimeToLive
foreach ($result in $results) {
if ($results.StatusCode -eq 0) {
if ($TTL -ge 98 -and $TTL -le 128)
{Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL,It is a Windows host." -ForegroundColor Green }
else
{Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL, It is NOT a Windows host." -ForegroundColor Blue}
}
else {
Write-Host "`n$_ Ping failed!" -ForegroundColor Red
}
}
}
}
cls
Get-Content c:\IP.txt | Ping_Test
结果:
相关文章推荐
- PowerShell实战1:Ping_Test
- PowerShell实战1:Ping_Test 推荐
- python实战系列之批量主机ping网络测试(七)
- PowerShell 操作 Azure SQL Active Geo-Replication 实战
- PowerShell实战 第二回 管理AD用户对象
- Linux下Google Test测试环境安装和使用,实战总结
- 【实战】电脑 开发板 虚拟机三者互ping通教程
- 【独立开发者er Cocos2d-x实战 014】Cocos2dx中的TestCPP运行Box2dTest
- PowerShell实战3:IAS服务器认证日志
- PowerShell实战5: 批量增加AD组成员
- Powershell快速入门(三) 实战应用
- Powershell 工作流实战(1)
- PowerShell 操作 Azure SQL Active Geo-Replication 实战
- PowerShell脚本简单使用 检测网络状况 date ping
- PowerShell实战 第三回 管理AD OU对象
- powershell ping 网段
- 云端卫士实战录 | OFTest 的安装和使用
- 跟我学VMM testbech (4)---实战 MP2991
- PowerShell实战5: 批量增加AD组成员
- 机器学习实战KNN一节中datingClassTest函数中的file2matrix(datingTestSet.txt)应为file2matrix(datingTestSet.txt)