标题: [文本处理] ping地址并输出IP的对应目标名称。 [打印本页]
作者: shengzhoul 时间: 2021-11-30 19:47 标题: 求助批处理Ping完不通的IP地址找出对应的名字编号
求助 Ping完不通的IP地址找出对应的名字编号- @echo on
- del D:\1\adb\63butong.txt
- del D:\1\adb\63tong.txt
- chcp 437
- goto:63
- set /p temp=:
- if /I "%temp%"=="62" goto :62
- if /I "%temp%"=="63" goto :63
- if /I "%temp%"=="64" goto :64
- if /I "%temp%"=="3" goto :3
- if /I "%temp%"=="4" goto :4
- if /I "%temp%"=="6" goto :6
- if /I "%temp%"=="7" goto :7
- if /I "%temp%"=="5" goto :5
- if /I "%temp%"=="226" goto :226
- if /I "%temp%"=="236" goto :236
- if /I "%temp%"=="230" goto :230
- if /I "%temp%"=="234" goto :234
- if /I "%temp%"=="235" goto :235
- if /I "%temp%"=="229" goto :229
- if /I "%temp%"=="228" goto :228
- if /I "%temp%"=="227" goto :227
- if /I "%temp%"=="231" goto :231
- if /I "%temp%"=="224" goto :224
- if /I "%temp%"=="225" goto :225
- if /I "%temp%"=="238" goto :238
- if /I "%temp%"=="r" goto :r
- :63
- setlocal enabledelayedexpansion
- for /f %%a in (a.txt) do (
- ping -n 1 %%a >pinglog.txt
- For /f "skip=2 tokens=4 delims=: " %%c In ('find "statistics" pinglog.txt') Do set IP=%%c
- For /f "skip=2 tokens=4,7,11 delims=,( " %%j In ('find "Lost" pinglog.txt') Do set Sent=%%j&set Received=%%k&set Lost=%%l
- For /f "skip=2 tokens=3,6,9 delims=, " %%m In ('find "Average" pinglog.txt') Do set Minimum=%%m&set Maximum=%%n&set Average=%%o
- For /f "tokens=3" %%y in ('find /c "Request timed out" pinglog.txt') do set Count=%%y
- if !Count! neq 0 echo TIME OUT IPAddress=!IP! Sent=!Sent! Received=!Received! Lost=!Lost! Minimum=!Minimum! Maximum=!Maximum! Average=!Average >>d:\1\abd\123.txt
- findstr /c:"Destination" pinglog.txt && echo %date%%time% Unreachable IPAddress=!IP! Sent=!Sent! Received=!Received! Lost=!Lost!>>63butong.txt
- findstr /c:"Request" pinglog.txt && echo %date%%time% Unreachable IPAddress=!IP! Sent=!Sent! Received=!Received! Lost=!Lost!>>63butong.txt
- echo, !%%j! >>63butong.txt
- findstr /c:"TTL=" pinglog.txt && echo !IP! >>63tong.txt
- butong
- )
- pause
复制代码
作者: shengzhoul 时间: 2021-11-30 20:30 标题: ping地址并输出IP的对应目标名称。
我们单位的局域网包含有两百多个IP地址,每一个IP地址对应一个固定的目标名称,现在,我要编一个批处理命令,用PING去ping每一个IP地址,然后,ping不通的就用》输出到一个txt文件上,要求是不光输出IP地址,还要显示输出相对就的目标名称,比如11.102.203.77是一楼,11.102.203.77是大门!谢谢!各位老师指教!
作者: flashercs 时间: 2021-11-30 22:53
- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- pause
- exit /b
- #>
- $htIPs = @{
- '192.168.82.1' = '网关'
- '192.168.82.2' = 'PC1'
- '192.168.82.3' = 'PC2'
- '192.168.82.4' = 'PC3'
- '192.168.82.5' = 'OPPO1'
- }
- Test-Connection -AsJob -ComputerName @($htIPs.Keys) -Count 1 | Wait-Job | Receive-Job | Where-Object { $_.StatusCode -ne 0 } | ForEach-Object {
- '{0} {1}' -f @($_.Address, $htIPs[$_.Address])
- } | Set-Content -Path 'disconnected.txt'
复制代码
作者: shengzhoul 时间: 2021-12-1 15:45
回复 3# flashercs
谢谢大师!
作者: 小二黑 时间: 2021-12-1 16:20
学习了,谢谢。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |