<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Определить шлюз или default route?]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6793&amp;type=atom" />
	<updated>2012-02-29T06:52:17Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6793</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57333#p57333" />
			<content type="html"><![CDATA[<p>Меня устроил мой вариант.. я слегка модернизировал ваш и получил вот это:</p><div class="codebox"><pre><code>echo off
setlocal ENABLEDELAYEDEXPANSION

set n=-1
::wmic nicconfig where ipenabled=true get DefaultIPGateway /format:value
for /f %%x in (&#039;wmic nicconfig where ipenabled^=true get DefaultIPGateway /format:value ^| find /i &quot;DefaultIPGateway&quot;&#039;) do (
    set /a n=!n! + 1
    set &quot;%%x&quot;
    set DefaultIPGateway=!DefaultIPGateway:&quot;=!
    set DefaultIPGateway=!DefaultIPGateway:{=!
    set DefaultIPGateway=!DefaultIPGateway:}=!
    set DefaultIPGateway_!n!=!DefaultIPGateway!
)

set newname=%COMPUTERNAME%_%DATE%
 echo !%newname% &gt;&gt; C:\inet.log

for /l %%x in (0,1,!n!) do (
    echo !DefaultIPGateway_%%x! &gt;&gt; C:\inet.log
)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[stir]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26486</uri>
			</author>
			<updated>2012-02-29T06:52:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57333#p57333</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57309#p57309" />
			<content type="html"><![CDATA[<p>Делаю так<br /></p><div class="codebox"><pre><code>@ECHO Alive work fine - %DATE%%TIME% via !DefaultIPGateway_%%x! &gt;&gt; C:\inet.log</code></pre></div><p>В итоге получаю </p><div class="quotebox"><blockquote><p>Alive work fine - 28.02.201218:07:48,60 via !DefaultIPGateway_%x!</p></blockquote></div><p>Что делаю не верно?</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-28T14:08:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57309#p57309</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57143#p57143" />
			<content type="html"><![CDATA[<p>так же</p><p>...(<br />&nbsp; &nbsp; echo !DefaultIPGateway_%%x! &gt;&gt; C:\inet.log<br />)</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-02-22T03:51:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57143#p57143</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57136#p57136" />
			<content type="html"><![CDATA[<p>Еще вопрос, как мне добавить в эту часть<br /></p><div class="codebox"><pre><code>@echo &quot;Inet work - %DATE%%TIME%&quot; &gt;&gt; C:\inet.log</code></pre></div><p>Вывод из <br /></p><div class="codebox"><pre><code>echo off
setlocal ENABLEDELAYEDEXPANSION

set n=-1
::wmic nicconfig where ipenabled=true get DefaultIPGateway /format:value
for /f %%x in (&#039;wmic nicconfig where ipenabled^=true get DefaultIPGateway /format:value ^| find /i &quot;DefaultIPGateway&quot;&#039;) do (
    set /a n=!n! + 1
    set &quot;%%x&quot;
    set DefaultIPGateway=!DefaultIPGateway:&quot;=!
    set DefaultIPGateway=!DefaultIPGateway:{=!
    set DefaultIPGateway=!DefaultIPGateway:}=!
    set DefaultIPGateway_!n!=!DefaultIPGateway!
)
for /l %%x in (0,1,!n!) do (
    echo !DefaultIPGateway_%%x!
)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-21T13:13:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57136#p57136</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57132#p57132" />
			<content type="html"><![CDATA[<p>Спасибо.</p><div class="quotebox"><blockquote><p>echo off</p></blockquote></div><p>Заменить на <br />@echo off</p><p>Этот способ даже в 7ке нормально отрабатывает.</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-21T07:16:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57132#p57132</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57121#p57121" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>echo off
setlocal ENABLEDELAYEDEXPANSION

set n=-1
::wmic nicconfig where ipenabled=true get DefaultIPGateway /format:value
for /f %%x in (&#039;wmic nicconfig where ipenabled^=true get DefaultIPGateway /format:value ^| find /i &quot;DefaultIPGateway&quot;&#039;) do (
    set /a n=!n! + 1
    set &quot;%%x&quot;
    set DefaultIPGateway=!DefaultIPGateway:&quot;=!
    set DefaultIPGateway=!DefaultIPGateway:{=!
    set DefaultIPGateway=!DefaultIPGateway:}=!
    set DefaultIPGateway_!n!=!DefaultIPGateway!
)
for /l %%x in (0,1,!n!) do (
    echo !DefaultIPGateway_%%x!
)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-02-20T18:56:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57121#p57121</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57112#p57112" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>Пойдет ?<br /></p><div class="codebox"><pre><code>for /f &quot;tokens=3&quot; %%x in (&#039;route print 0.0.0.0 ^| find &quot;0.0.0.0&quot;&#039;) do echo %%x</code></pre></div></blockquote></div><p>Данный способ не всегда отрабатывает верно.<br />Может есть еще пути определения? <br />wmic?</p><p>NICCONFIG GET DefaultIPGateway выдаст, примерно вот такую инфу. <br /></p><div class="quotebox"><blockquote><p>wmic:root\cli&gt;NICCONFIG GET DefaultIPGateway<br />DefaultIPGateway<br />{&quot;192.168.2.101&quot;}</p></blockquote></div><p>Но вот вопрос, как убрать пробелы и не нужные знаки?</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-20T14:17:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57112#p57112</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56735#p56735" />
			<content type="html"><![CDATA[<p>Отличный, ход. Я об этом не подумал.</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-13T07:45:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56735#p56735</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56732#p56732" />
			<content type="html"><![CDATA[<p>Пойдет ?<br /></p><div class="codebox"><pre><code>for /f &quot;tokens=3&quot; %%x in (&#039;route print 0.0.0.0 ^| find &quot;0.0.0.0&quot;&#039;) do echo %%x</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-02-13T07:36:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56732#p56732</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56729#p56729" />
			<content type="html"><![CDATA[<p>Поясню в windows шлюз можно посмотреть командой ipconfig /all или route print<br />===========================================================================<br />Постоянные маршруты:<br />&nbsp; Сетевой адрес&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Маска&nbsp; &nbsp; Адрес шлюза&nbsp; &nbsp; &nbsp; Метрика<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0&nbsp; &nbsp; 192.168.1.200&nbsp; По умолчанию<br />===========================================================================</p><p>Или</p><p>&nbsp; &nbsp;Основной шлюз. . . . . . . . . : 192.168.1.200<br />&nbsp; &nbsp;DNS-серверы. . . . . . . . . . . : 192.168.1.101<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;192.168.1.200<br />Так вот интересует как через cmd сценарий получить именно 192.168.1.200, только этот набор цифр, а остальное обрезать. </p><p>Еще можно получить с помощью пару средств, но они реже используются.</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-13T04:43:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56729#p56729</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56678#p56678" />
			<content type="html"><![CDATA[<p>не совсем понял, определение текущего шлюза или переназначение основного шлюза ?<br />route change ... ?</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-02-11T12:33:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56678#p56678</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: Определить шлюз или default route?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56601#p56601" />
			<content type="html"><![CDATA[<p>Добрый день, всем. </p><p>Есть вот такой cmd скрипт<br /></p><div class="codebox"><pre><code>@echo off
SET GW101=192.168.2.101
SET GW102=192.168.2.102
SET GW222=192.168.2.222

SET PING=ping -n 2 ya.ru &gt; nul
SET GATEWAY101=netsh interface ip set address name=&quot;local&quot; gateway=%GW101% gwmetric=0
SET GATEWAY102=netsh interface ip set address name=&quot;local&quot; gateway=%GW102% gwmetric=0
SET GATEWAY222=netsh interface ip set address name=&quot;local&quot; gateway=%GW222% gwmetric=0

@%PING%
@IF ERRORLEVEL 1 GOTO route2
@IF ERRORLEVEL 0 GOTO alive

:route2
@%GATEWAY102%
@ECHO &quot;Change route on %GW102% gateway at %DATE%%TIME%&quot; &gt;&gt; C:\inet.log
@%PING%
@IF ERRORLEVEL 1 GOTO route3
@IF ERRORLEVEL 0 GOTO alive
@GOTO end

:route3
@%GATEWAY222%
@ECHO &quot;Change route on %GW222% gateway at %DATE%%TIME%&quot; &gt;&gt; C:\inet.log
@%PING%
@IF ERRORLEVEL 1 GOTO route1
@IF ERRORLEVEL 0 GOTO alive
@GOTO end

:route1
@%GATEWAY101%
@ECHO &quot;Change route on %GW101% gateway at %DATE%%TIME%&quot; &gt;&gt; C:\inet.log
@%PING%
@IF ERRORLEVEL 1 GOTO end
@IF ERRORLEVEL 0 GOTO alive


:alive
@echo &quot;Inet work - %DATE%%TIME%&quot; &gt;&gt; C:\inet.log
@ECHO Alive
@GOTO end

:end
@ECHO Goodbye</code></pre></div><p>мне нужно добавить определение шлюза или маршрута по умолчанию. Посоветуйте плиз.</p>]]></content>
			<author>
				<name><![CDATA[Valera]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2611</uri>
			</author>
			<updated>2012-02-09T14:33:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56601#p56601</id>
		</entry>
</feed>
