::----------------------------------------------------------------------------------------------- :: IPAddress Usage ::----------------------------------------------------------------------------------------------- :: Call IPAddress [/cache /usecache /cachefile Filename] :: :: The /Cache switch causes the program to not delete temp files :: The /Usecache switch tells it to read from cached files, data may be out of date :: The /Cachefile filename switch changes default location of cached files :: :: Calling procedure must use Delayed Variables! :: Use SetLocal ENABLEDELAYEDEXPANSION command in calling batch file :: Returns These Variables: ::----------------------------------------------------------------------------------------------- ::%IPAddress.NumberOfAddresses% = Number of IP Addresses :: ::IP Addresses: ::%IPAddress1%,%IPAddress2%, ect.. = Returns the IP Address as a dotted quad ::%IPAddress1.A%,%IPAddress1.B%,ect.. = Returns each octect of the IP Address ::%IPAddress1.A.Bin%,%IPAddress1.B.Bin%,ect.. = Returns binary value of each octect :: ::Subnet Masks: ::%IPAddress1.SubnetMask%,ect.. = Returns the IP Address's Subnet Mask as a dotted quad ::%IPAddress1.SubnetMask.Bin%,,ect.. = Returns binary value of the subnet mask ::%IPAddress1.SubnetMask.A%,ect.. = Returns each octect of the IP Address's Subnet Mask ::%IPAddress1.SubnetMask.A.Bin%,,ect.. = Returns binary value of each octect in the subnet mask :: ::Default Gateways: ::%IPAddress1.DefaultGateWay% = Returns IP Address's Default Gateway ::%IPAddress1.DefaultGateway.A% = Returns First Octect of Default Gateway ::Default Gateway does NOT return any binary values :: ::Network: ::%IPAddress1.Network% = Returns Network of IP Address ::%IPAddress1.Network.Bin% = Returns Binary Value of Network ::%IPAddress1.Network.A% = Returns Dotted Quads of Network ::%IPAddress1.Network.A.Bin% = Returns Binary Value of each dotted quad in network ::----------------------------------------------------------------------------------------------- Goto :Main ::--------------:: ::SimpleDecToBin:: ::--------------:: :DecToBin Set TempNumber=%1 If %TempNumber% GEQ 128 ( Set /a TempNumber-=128 Set Bin=1) Else ( Set Bin=0) If %TempNumber% GEQ 64 ( Set /a TempNumber-=64 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 32 ( Set /a TempNumber-=32 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 16 ( Set /a TempNumber-=16 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 8 ( Set /a TempNumber-=8 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 4 ( Set /a TempNumber-=4 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 2 ( Set /a TempNumber-=2 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) If %TempNumber% GEQ 1 ( Set /a TempNumber-=1 Set Bin=%Bin%1) Else ( Set Bin=%Bin%0) Set TempNumber= Goto :Eof ::--------------:: ::SimpleBinToDec:: ::--------------:: :BinToDec Set TempNumber=%1 If "%TempNumber:~0,1%"=="1" (Set Dec=128) else (Set Dec=0) If "%TempNumber:~1,1%"=="1" Set /a Dec+=64 If "%TempNumber:~2,1%"=="1" Set /a Dec+=32 If "%TempNumber:~3,1%"=="1" Set /a Dec+=16 If "%TempNumber:~4,1%"=="1" Set /a Dec+=8 If "%TempNumber:~5,1%"=="1" Set /a Dec+=4 If "%TempNumber:~6,1%"=="1" Set /a Dec+=2 If "%TempNumber:~7,1%"=="1" Set /a Dec+=1 Goto :Eof ::---------:: ::SimpleAND:: ::---------:: :SimpleAND Set Number=%1 Set Mask=%2 Set ANDed= For /l %%a in (0,1,7) do ( If "!Number:~%%a,1!"=="!Mask:~%%a,1!" ( Set ANDed=!ANDed!!Number:~%%a,1! ) else (Set ANDed=!ANDed!0) ) Goto :Eof :Main ::--------------:: ::Get Parameters:: ::--------------:: :ParamLoop if "%~1"=="" goto DefaultConfig Set Tempparm=%~1 if /i "%TempParm:~1,9%"=="cache" Set KeepFile=True if /i "%TempParm:~1,8%"=="usecache" Set UseCache=True if /i "%TempParm:~1,9%"=="cachefile" ( Set FileLocation=%~2 Shift ) Shift if "%~1"=="" goto Start Goto ParamLoop ::------------:: ::Set Defaults:: ::------------:: :DefaultConfig Set FileLocation=%~0 :start If not "%usecache%"=="True" Ipconfig > "%FileLocation%.temp" ::----------------:: ::Get IP Addresses:: ::----------------:: If not "%usecache%"=="True" Type "%FileLocation%.temp" | find "IP Address" > "%FileLocation%IP.temp" Set IPAddress.NumberOfAddresses=0 for /f "Tokens=3,4,5,6 Delims=:. " %%a in (%FileLocation%IP.temp) do ( Set /a IPAddress.NumberOfAddresses+=1 Set IPAddress!IPAddress.NumberOfAddresses!=%%a.%%b.%%c.%%d Set IPAddress!IPAddress.NumberOfAddresses!.a=%%a Set IPAddress!IPAddress.NumberOfAddresses!.b=%%b Set IPAddress!IPAddress.NumberOfAddresses!.c=%%c Set IPAddress!IPAddress.NumberOfAddresses!.d=%%d Call :DecToBin %%a Set IPAddress!IPAddress.NumberOfAddresses!.a.bin=!Bin! Set TempMask=!Bin!. Call :DecToBin %%b Set IPAddress!IPAddress.NumberOfAddresses!.b.bin=!Bin! Set TempMask=!TempMask!!Bin!. Call :DecToBin %%c Set IPAddress!IPAddress.NumberOfAddresses!.c.bin=!Bin! Set TempMask=!TempMask!!Bin!. Call :DecToBin %%d Set IPAddress!IPAddress.NumberOfAddresses!.d.bin=!Bin! Set TempMask=!TempMask!!Bin! Set IPAddress!IPAddress.NumberOfAddresses!.bin=!TempMask! ) If not "%KeepFile%"=="True" Del "%FileLocation%IP.temp" ::----------------:: ::Get Subnet Masks:: ::----------------:: If not "%usecache%"=="True" Type "%FileLocation%.temp" | find "Subnet Mask" > "%FileLocation%Sub.temp" Set IPAddress.NumberOfAddresses=0 for /f "Tokens=3,4,5,6 Delims=:. " %%a in (%FileLocation%Sub.temp) do ( Set /a IPAddress.NumberOfAddresses+=1 Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask=%%a.%%b.%%c.%%d Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.a=%%a Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.b=%%b Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.c=%%c Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.d=%%d Call :DecToBin %%a Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.a.bin=!Bin! Set TempMask=!Bin!. Call :DecToBin %%b Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.b.bin=!Bin! Set TempMask=!TempMask!!Bin!. Call :DecToBin %%c Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.c.bin=!Bin! Set TempMask=!TempMask!!Bin!. Call :DecToBin %%d Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.d.bin=!Bin! Set TempMask=!TempMask!!Bin! Set IPAddress!IPAddress.NumberOfAddresses!.SubnetMask.bin=!TempMask! ) If not "%KeepFile%"=="True" Del "%FileLocation%Sub.temp" ::------------:: ::Get Gateways:: ::------------:: If not "%usecache%"=="True" Type "%FileLocation%.temp" | find "Default Gate" > "%FileLocation%Gate.temp" Set IPAddress.NumberOfAddresses=0 for /f "Tokens=3,4,5,6 Delims=:. " %%a in (%FileLocation%Gate.temp) do ( Set /a IPAddress.NumberOfAddresses+=1 Set IPAddress!IPAddress.NumberOfAddresses!.DefaultGateway=%%a.%%b.%%c.%%d Set IPAddress!IPAddress.NumberOfAddresses!.DefaultGateway.a=%%a Set IPAddress!IPAddress.NumberOfAddresses!.DefaultGateway.b=%%b Set IPAddress!IPAddress.NumberOfAddresses!.DefaultGateway.c=%%c Set IPAddress!IPAddress.NumberOfAddresses!.DefaultGateway.d=%%d ) If not "%KeepFile%"=="True" Del "%FileLocation%Gate.temp" ::-----------:: ::Get Network:: ::-----------:: For /l %%a in (1,1,%IPAddress.NumberofAddresses%) do ( Call :SimpleAnd !IPAddress%%a.a.bin! !IPAddress%%a.SubnetMask.a.bin! Set IPAddress%%a.Network.A.Bin=!ANDed! Set TempMask=!ANDed!. Call :BinToDec !ANDed! Set IPAddress%%a.Network.A.=!Dec! Set TempMask2=!Dec! Call :SimpleAnd !IPAddress%%a.B.bin! !IPAddress%%a.SubnetMask.b.bin! Set IPAddress%%a.Network.B.Bin=!ANDed! Set TempMask=!TempMask!!ANDed!. Call :BinToDec !ANDed! Set IPAddress%%a.Network.B.=!Dec! Set TempMask2=!TempMask2!.!Dec! Call :SimpleAnd !IPAddress%%a.C.bin! !IPAddress%%a.SubnetMask.c.bin! Set IPAddress%%a.Network.C.Bin=!ANDed! Set TempMask=!TempMask!!ANDed!. Call :BinToDec !ANDed! Set IPAddress%%a.Network.C.=!Dec! Set TempMask2=!TempMask2!.!Dec! Call :SimpleAnd !IPAddress%%a.D.bin! !IPAddress%%a.SubnetMask.d.bin! Set IPAddress%%a.Network.D.Bin=!ANDed! Set IPAddress%%a.Network.Bin=!TempMask!!ANDed! Call :BinToDec !ANDed! Set IPAddress%%a.Network.D.=!Dec! Set IPAddress%%a.Network=!TempMask2!.!Dec! ) del "%FileLocation%.temp"