Я делаю простой пакетный скрипт для проверки связи с хостом и проверки его соединения. Это мой код:
@ECHO OFF
@powershell -ExecutionPolicy UnRestricted -Command "(Add-Type -memberDefinition \"[DllImport(\"\"user32.dll\"\")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x,int y,int cx, int xy, uint flagsw);\" -name \"Win32SetWindowPos\" -passThru )::SetWindowPos((Add-Type -memberDefinition \"[DllImport(\"\"Kernel32.dll\"\")] public static extern IntPtr GetConsoleWindow();\" -name \"Win32GetConsoleWindow\" -passThru )::GetConsoleWindow(),-1,0,0,0,0,67)"
title Ping tool
mode con: cols=50 lines=25
:PING
cls & set /p address= [*] Host to ping:
@echo [*] Started pinging at: %time%
title Pinging %address%
if %ERRORLEVEL% == 1 echo Host didn't respond.
ping %address% -t & echo. & pause. & goto :PING
Я пытаюсь сделать так, чтобы, когда я получаю код ошибки (Запрос истек), он выдает «Хост не ответил» вместо обычного. Однако это не работает.
Обычно мой пинг выдает следующее:
[*] Host to ping: 8.8.8.8
[*] Started pinging at: 13:44:29.05
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=28ms TTL=52
Reply from 8.8.8.8: bytes=32 time=16ms TTL=52
Request timed out.
Request timed out.
et c.
Но я хочу, чтобы это выглядело так:
[*] Host to ping: 8.8.8.8
[*] Started pinging at: 13:44:29.05
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=28ms TTL=52
Reply from 8.8.8.8: bytes=32 time=16ms TTL=52
Host didn't respond.
Host didn't respond.
Как бы я go сделал это?
PS Вторая строка скрипта - это команда что я нашел здесь , что делает окно CMD всегда сверху. Очень полезно!