<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Phylum's Feed - Programmer's Heaven</title>
    <link>http://www.programmersheaven.com/feed/User/499975/RSS.aspx</link>
    <description>Events at Programmer's Heaven related to the user Phylum.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 03:38:20 -0700</pubDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <item>
      <title>Re: batch file with arithmatic operations on ip addresses</title>
      <link>http://www.programmersheaven.com/mb/MS-DOS/370895/419870/ReadMessage.aspx#419870</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/MS-DOS/370895/419870/ReadMessage.aspx#419870"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/MS-DOS/Board.aspx"&gt;MS-DOS&lt;/a&gt; forum.&lt;/p&gt;My two cents&lt;br /&gt;
&lt;br /&gt;
I'm thinking this process will need to be broken down into chunks in order to do what needs to be done.&lt;br /&gt;
&lt;br /&gt;
So first we'll need the gateway &lt;br /&gt;
&lt;br /&gt;
:: Get the Gateway&lt;br /&gt;
for /F "usebackq tokens=13" %%i in (`ipconfig ^| find /i "gateway"`) do set gateway=%%i&lt;br /&gt;
&lt;br /&gt;
You can use a similar technique for getting the IP address&lt;br /&gt;
for /F "usebackq tokens=14" %%i in (`ipconfig ^| find /i "IPv4"`) do echo %%i&lt;br /&gt;
&lt;br /&gt;
(Note: I was trying to make use of the 'delims' option but I wound up with extra spaces I didn't want to have to deal with trimming.  For example, the following would return " 192.168.1.2" instead of "192.168.1.2"&lt;br /&gt;
&lt;br /&gt;
for /F "usebackq tokens=2 delims=:" %i in (`ipconfig ^| find /i "IPv4"`) do echo %i&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
for /F "usebackq tokens=13 delims=: " %i in (`ipconfig ^| find /i "IPv4"`) do echo %i&lt;br /&gt;
&lt;br /&gt;
Any ideas on overcoming this?)&lt;br /&gt;
&lt;br /&gt;
Next I'm thinking you'll probably need to split the IP at some point; I recommend using a subroutine of sorts.&lt;br /&gt;
&lt;br /&gt;
CALL :SPLITIP %gateway%&lt;br /&gt;
&lt;br /&gt;
:SPLITIP&lt;br /&gt;
:: Split IP into Separate Octects&lt;br /&gt;
set IP=%1&lt;br /&gt;
if defined IP (&lt;br /&gt;
	for /F "usebackq delims=. tokens=1-4" %%i in (`echo %IP%`) do (&lt;br /&gt;
		set GIPO1=%%i&lt;br /&gt;
		set GIPO2=%%j&lt;br /&gt;
		set GIPO3=%%k&lt;br /&gt;
		set GIPO4=%%l&lt;br /&gt;
	)&lt;br /&gt;
) else ( echo ERROR: Gateway Not Defined (%gateway%) &amp;amp; ping -n 30 localhost &amp;gt;nul &amp;amp; goto END )&lt;br /&gt;
rem for %%i in (%GIPO1% %GIPO2% %GIPO3% %GIPO4%) do echo %%i&lt;br /&gt;
GOTO :EOF&lt;br /&gt;
&lt;br /&gt;
At at some point you may need to know the length of a variable or two in order to do some advanced string manipulation.  I use yet another subroutine for that.&lt;br /&gt;
@echo off&lt;br /&gt;
cls&lt;br /&gt;
&lt;br /&gt;
set mystring=five&lt;br /&gt;
&lt;br /&gt;
CALL :GETLENGTH %mystring%&lt;br /&gt;
&lt;br /&gt;
:GETLENGTH&lt;br /&gt;
:: Send the length of the variable %1 to the variable %var_length%&lt;br /&gt;
:: Thanks to Leonardo Pignataro secret_doom@hotmail.com www.batch.hpg.com.br&lt;br /&gt;
set length_target=%1&lt;br /&gt;
set var_length=0&lt;br /&gt;
:GLoop&lt;br /&gt;
if defined length_target (&lt;br /&gt;
	set length_target=%length_target:~1%&lt;br /&gt;
	set /A var_length += 1&lt;br /&gt;
	goto GLoop&lt;br /&gt;
)&lt;br /&gt;
echo Var is %var_length% characters long!&lt;br /&gt;
GOTO :EOF&lt;br /&gt;
&lt;br /&gt;
This should return "Var is 5 characters long!"&lt;br /&gt;
&lt;br /&gt;
Haven't throughly tested any of this code, but it should be good.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/MS-DOS/370895/419870/ReadMessage.aspx#419870</guid>
      <pubDate>Mon, 22 Nov 2010 11:16:06 -0700</pubDate>
    </item>
  </channel>
</rss>