<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Цикл для ping]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11488&amp;type=atom" />
	<updated>2016-07-12T11:56:51Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11488</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Цикл для ping]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=106050#p106050" />
			<content type="html"><![CDATA[<p>Пытался понять последний скрипт - разложить &quot;красиво&quot;, но он не работает. Что не так?</p><div class="codebox"><pre><code>@echo off


:: ---------- задаем переменные -------------

:: задаем узлы для тестирования доступа
set IP_for_test=&quot;0.0.0.0&quot; &quot;1.1.1.1&quot; &quot;2.2.2.2&quot; &quot;3.3.3.3&quot; &quot;4.4.4.4&quot; &quot;5.5.5.5&quot; &quot;6.6.6.6&quot; &quot;7.7.7.7&quot; &quot;8.8.8.8&quot; &quot;9.9.9.9&quot;

:: задаем путь к папке с логом
set &quot;log_dir=C:\scripts\test_connect&quot;

:: задаем количество пакетов для оценки
set &quot;num_packets=20&quot;

:: задаем таймаут для каждого ответа
set &quot;ping_timeout=1000&quot;

:: -------------------------------------------


:: проверяем наличие папки для лога
if not exist &quot;%log_dir%&quot; md &quot;%log_dir%&quot;

for %%i in (%IP_for_test%) do (
	start &quot;&quot; /b cmd /v/c for /l %%j in () do @for /f %%k in (&#039;^ping -l 1 -n %num_packets% -w %ping_timeout% %%i^^^| find &quot;TTL=&quot;^^^| find/c /v &quot;&quot;&#039;) do @^^&gt;^&gt;&quot;%log_dir%\%%~i_log.txt&quot; (
		if %%k gtr 0 (
			echo !date! will have access to the %%~i in  !time!^&amp;^
			echo.
		) else (
			echo !date! lost access to the %%~i in  !time!
		)
	)
)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Александр_foxware]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26976</uri>
			</author>
			<updated>2016-07-12T11:56:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=106050#p106050</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Цикл для ping]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=102516#p102516" />
			<content type="html"><![CDATA[<p>Большое спасибо! Yury - сложное написание с перенаправлением результатов команд</p>]]></content>
			<author>
				<name><![CDATA[Александр_foxware]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26976</uri>
			</author>
			<updated>2016-04-12T08:39:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=102516#p102516</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Цикл для ping]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=102513#p102513" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Александр_foxware пишет:</cite><blockquote><p>Текущий скрипт...</p></blockquote></div><br /><br /><p>Не-а. Так не пойдёт. Нерабочий он.</p><p>Вот правильный код:</p><div class="codebox"><pre><code>@echo off
setlocal enabledelayedexpansion


:: ---------- задаем переменные -------------

:: задаем узел для тестирования доступа
set &quot;IP_for_test=8.8.8.8&quot;

:: задаем путь к папке с логом
set &quot;log_dir=C:\scripts\test_connect&quot;

:: задаем количество пакетов для оценки
set &quot;num_packets=20&quot;

:: задаем таймаут для каждого ответа
set &quot;ping_timeout=1000&quot;

:: -------------------------------------------


:: проверяем наличие папки для лога
if not exist &quot;%log_dir%&quot; md &quot;%log_dir%&quot;


:starttesting

	ping.exe -l 1 -n %num_packets% -w %ping_timeout% %IP_for_test% | &gt;nul find &quot;TTL=&quot;

	&gt;&gt;&quot;%log_dir%\%IP_for_test%_log.txt&quot; (
		if !errorlevel!==1 (
			echo !date! lost access to the %IP_for_test% in  !time!
		) else (
			echo !date! will have access to the %IP_for_test% in  !time!
			echo.
		)
	)

goto starttesting</code></pre></div><p>.</p><p>А вот код, который Вам нужен:</p><div class="codebox"><pre><code>@echo off


:: ---------- задаем переменные -------------

:: задаем узлы для тестирования доступа
set IP_for_test=&quot;0.0.0.0&quot; &quot;1.1.1.1&quot; &quot;2.2.2.2&quot; &quot;3.3.3.3&quot; &quot;4.4.4.4&quot; &quot;5.5.5.5&quot; &quot;6.6.6.6&quot; &quot;7.7.7.7&quot; &quot;8.8.8.8&quot; &quot;9.9.9.9&quot;

:: задаем путь к папке с логом
set &quot;log_dir=C:\scripts\test_connect&quot;

:: задаем количество пакетов для оценки
set &quot;num_packets=20&quot;

:: задаем таймаут для каждого ответа
set &quot;ping_timeout=1000&quot;

:: -------------------------------------------


:: проверяем наличие папки для лога
if not exist &quot;%log_dir%&quot; md &quot;%log_dir%&quot;

for %%i in (%IP_for_test%) do start &quot;&quot; /b cmd /v/c for /l %%j in () do @for /f %%k in (&#039;^
 ping -l 1 -n %num_packets% -w %ping_timeout% %%i^^^| find &quot;TTL=&quot;^^^| find/c /v &quot;&quot;&#039;) do @^
  ^&gt;^&gt;&quot;%log_dir%\%%~i_log.txt&quot; (if %%k gtr 0 (echo !date! will have access to the %%~i in  !time!^&amp;^
   echo.) else echo !date! lost access to the %%~i in  !time!)</code></pre></div><p>.</p>]]></content>
			<author>
				<name><![CDATA[Yury]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30230</uri>
			</author>
			<updated>2016-04-12T01:55:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=102513#p102513</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: Цикл для ping]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=102481#p102481" />
			<content type="html"><![CDATA[<p>Добрый день! У меня давно был написан простой скрипт для проверки доступности хоста с логированием. Хотел добавить в скрипт проверку сразу нескольких хостов, но не получается. Пробовал через команду &quot;start&quot;, но не получается отлавливать результат команды &quot;ping&quot;.</p><p>Текущий скрипт:</p><div class="codebox"><pre><code>@ECHO OFF
COLOR 0A

:: ---------- задаем переменные -------------

:: задаем узел для тестирования доступа
set IP_for_test=8.8.8.8

:: задаем путь к папке с логом
set log_dir=C:\scripts\test_connect

:: задаем количество пакетов для оценки
set num_packets=20

:: задаем таймаут для каждого ответа
set ping_timeout=1000

:: -------------------------------------------


set badaccess=0
set goodaccess=1

:: проверяем наличие папки для лога
if not exist %log_dir% md %log_dir%

:starttesting

ping.exe -l 1 -n %num_packets% -w %ping_timeout% %IP_for_test% | find &quot;TTL=&quot; &gt; nul
if %errorlevel%==1 (
	set badaccess=1
	if %goodaccess%==1 echo %date% lost access to the %IP_for_test% in  %time% &gt;&gt; %log_dir%\%IP_for_test%_log.txt
	set goodaccess=0
) else (
	set goodaccess=1
	if %badaccess%==1 echo %date% will have access to the %IP_for_test% in  %time% &gt;&gt; %log_dir%\%IP_for_test%_log.txt
	if %badaccess%==1 echo. &gt;&gt; %log_dir%\%IP_for_test%_log.txt
	set badaccess=0
)

goto :starttesting

exit /b 0</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Александр_foxware]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26976</uri>
			</author>
			<updated>2016-04-11T09:23:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=102481#p102481</id>
		</entry>
</feed>
