@echo off @setlocal enabledelayedexpansion @rem ---------------------------------------------------------------------- rem@ @rem Main Cycle rem@ @rem ---------------------------------------------------------------------- rem@ @rem Resetting global variables @set rnum=0 @set arstr1= @set arstr2= @set _tmp0= @set _tmp1= @set _tmp2= @set _tmp3= @set _tmp4= @set _tmp5= @set bytea=0 @set byteb=0 @set bytec=0 @set byted=0 @set bytex=0 @set delta=0 @set decmask=0 @set maskflag=0 @set counter0=1 @set counter1=0 @set WF=list @set scriptName=IPConfig.vbs @set scriptPath=%temp% @set scrOut="%scriptPath%\%scriptName%" @rem Done with reset. @rem Reading script parameters. @if "%1"=="" @call:init1 && @call:dumparrays && @goto:eof @if "%1"=="-l" @call:init1 && @call:dumparrays && @goto:eof @if "%1"=="-a" @if "%2"=="-u" @call:scriptlist && @goto:eof @if "%1"=="-a" @call:init1 && @call:dumparraysverbose && @goto:eof @if "%1"=="-h" @call:usage && @goto:eof @if "%1"=="-m" @set decmask=%2 && @call:printmask && @goto:eof @set WF=notlist @for /F "delims=0123456789 tokens=1" %%a in ("%1") do @if "%%a"=="eth" @set WF=ether && @goto:work @set WF=notether :work @echo %WF% goto:eof @rem Done with reading script parameters. @call:init1 @call:dumparrays @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Subprocedures rem@ @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Init 1 :init1 @rem Filling two string arrays with result of dump. @For /F "tokens=*" %%q in ('@netsh dump ^| find "add interface" ^| find "state"') do ( @set "istr=%%q" @set istr=!istr:"=;! @set istr=!istr:;;=! @call:changerdelims @set %arstr2=!arstr2!!_tmp0!; @set %arstr1=!arstr1!eth!_tmp1!; ) @rem Done with filling arrays. @rem Counting their length. @call:countarraylength @rem Lower count by three to get correct result. @set /a counter0-=3 @rem Done with conting. @rem exiting. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem CountArrayLength :countarraylength @for /f "tokens=%counter0% delims=;" %%q in ("!arstr1!") do ( @set _tmp2=%%q @set /a counter0+=1 @if not .!_tmp2!==. @goto:countarraylength ) @rem Count complete. @rem exiting. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Changer Delims :changerdelims @For /F "tokens=2 delims=;" %%q in ("!istr!") do ( @set /a rnum+=1 @set _tmp0=%%q @set _tmp1=%rnum% ) @rem Delims change complete. @rem exiting. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Dump Arrays :dumparrays @if %counter0% LSS 0 @echo No interfaces found or you don't have admin privileges. && @echo Try to run ifconfig in user mode (with -u key) instead. && @echo For more information, run 'ifconfig -h'. && @goto:eof @set /a counter1+=1 @for /F "tokens=%counter1% delims=;" %%q in ("!arstr1!") do @set _tmp3=%%q @for /F "tokens=%counter1% delims=;" %%q in ("!arstr2!") do @set _tmp4=%%q @echo !_tmp3!:name="!_tmp4!" @if not %counter1%==%counter0% goto:dumparrays ) @rem Done with dumping arrays. @rem exiting. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Dump Arrays Verbose :dumparraysverbose @if %counter0% LSS 0 @echo No interfaces found or you don't have admin privileges. && @echo Try to run ifconfig in user mode (with -u key) instead. && @echo For more information, run 'ifconfig -h'. && @goto:eof @set /a counter1+=1 @for /F "tokens=%counter1% delims=;" %%q in ("!arstr2!") do @set _tmp4=%%q @netsh interface ip show config "!_tmp4!" @if not %counter1%==%counter0% goto:dumparraysverbose ) @rem Done with dumping arrays verbose. @rem exiting. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- @rem @rem Printing mask. :printmask @for /l %%i in (1,1,32) do @set _tmp5=%%i && @if !_tmp5!==!decmask! @set maskflag=1 @if %maskflag%==0 @echo Invalid mask specified^! && @goto:eof @if %decmask% LEQ 8 @call:mask8 && @goto:echomask @if %decmask% LEQ 16 @call:mask16 && @goto:echomask @if %decmask% LEQ 24 @call:mask24 && @goto:echomask @if %decmask% LEQ 32 @call:mask32 && @goto:echomask :echomask @echo %bytea%.%byteb%.%bytec%.%byted% @rem Done printing mask. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Mask delta in first octet. :mask8 @set delta=%decmask% @call:calcdec @set bytea=%bytex% @rem Done with Mask delta in first octet. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Mask delta in second octet. :mask16 @set bytea=255 @set delta=%decmask% && @set /a delta-=8 @call:calcdec @set byteb=%bytex% @rem Done with Mask delta in second octet. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Mask delta in third octet. :mask24 @set bytea=255 @set byteb=255 @set delta=%decmask% && @set /a delta-=16 @call:calcdec @set bytec=%bytex% @rem Done with Mask delta in third octet. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Mask delta in fourth octet. :mask32 @set bytea=255 @set byteb=255 @set bytec=255 @set delta=%decmask% && @set /a delta-=24 @call:calcdec @set byted=%bytex% @rem Done with Mask delta in fourth octet. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Calculating Mask delta. :calcdec @if %delta% == 8 @set bytex=255 @if %delta% == 7 @set bytex=254 @if %delta% == 6 @set bytex=252 @if %delta% == 5 @set bytex=248 @if %delta% == 4 @set bytex=240 @if %delta% == 3 @set bytex=224 @if %delta% == 2 @set bytex=192 @if %delta% == 1 @set bytex=128 @if %delta% == 0 @set bytex=0 @rem Done with Calculating Mask delta. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- @rem @rem Usage :usage @rem Dumping simple text block. @echo # --------------------------------------------------------------------------- # @echo # Simple ifconfig script, written by Dmitry Stremkouski to manage local # @echo # network interfaces via unix-like cmd. # @echo # __ ------------------------------------------------------------------- # @echo # _--~ @echo ~ @echo. @echo Usage^: ifconfig [-a [-u]^|-h^|-l] [ethX [alias] ^ netmask ^ [up^|down] @echo. @echo If no keys or parameters provided - will do the same, as if you @echo run ifconfig script with "-l" key. @echo. @echo Keys: @echo ^^!NOTICE^^! If You use keys, parameters are unnecessary. @echo -l - List all known by Windows interfaces. @echo -a - List more verbose info about interfaces. @echo -u - User mode. Used with -a key only^! @echo ^^!NOTICE^^! Since netsh requires administrators privilegies, nevertheless @echo we use small hack with VBScript and registry. @echo Run: 'ifconfig -a -u' to use this trick. @echo ^^!NOTICE^^! Sometimes netsh crashes with "No more endpoints available" @echo error. Unfortunately, script will work then only in user mode. @echo -h - Will provide this help. @echo. @echo Parameters: @echo ethX - interface name alias. You can get list of aliases by @echo running "ifconfig -l". @echo ^ - IP address in decimal metric. @echo ^ - Netmask in decimal metric. @echo. @echo Examples: @echo ^^!WARNING^^! You should realy understand, that Windows does @echo not recognize VIRTUAL (VPN-like) interfaces. @echo ifconfig eth1 - Returns info about eth1 interface. @echo ifconfig eth2 192.168.0.50 netmask 255.255.255.0 @echo - Will assign THE ONLY ONE IP - 192.168.0.50 to eth2 @echo interface with netmask 255.255.255.0. @echo ^^!NOTICE^^! If You want to change IP configuration, netmask parameter @echo is NECESSARY. @echo ifconfig eth3 alias 192.168.0.49 netmask 255.255.255.252 @echo - Will assign additional IP to eth3 interface. @echo ifconfig eth1 up _-~ @echo - Will turn eth1 interface on. _ --_~ # @echo __--_- ~ Enjoy^^! # @echo # ----------------------------------------------------------~---------------- # @rem Done with dumping text block. @goto:eof @rem ---------------------------------------------------------------------- @rem @rem ---------------------------------------------------------------------- rem@ @rem Running external script. :scriptlist @call:genbanner @call:genheader @call:genbody @cscript //nologo %scrOut% @del %scrOut% /q @rem Done with Running external script. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Generating script banner. :genbanner @echo.>%scrOut% @echo ' ===----( * )----=== _ - _ --==-- _ - _ ===----( * )----=== '>>%scrOut% @echo ' _ - - - ~ ~ ~ .. ~ ~ ~ - - - _ _ ' >>%scrOut% @echo ' IPConfig.vbs script by Dzmitry Stremkouski ( http://mitroko.com ) 2008 ' >>%scrOut% @echo ' - _ _ _ _ - .--. - _ _ _ _ - - ' >>%scrOut% @echo ' ===--( * )--=== ~ _ - /\\/\\ - _ ~ ===--( * )--=== ' >>%scrOut% @echo ' ===--=== ===------=== . \\/\\/ . ===------=== ===--=== ' >>%scrOut% @echo Option explicit '.\ '::' /.' ticilpxe noitpO>>%scrOut% @echo ' - \ `` / - ' >>%scrOut% @echo ' F R E E D O M \/ M O D E E R F ' GPLv2. >>%scrOut% @echo ' / \ ' ===== >>%scrOut% @echo '8 8` >>%scrOut% @echo.>>%scrOut% @rem Done with Generating script banner. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Generating script header. :genheader @echo const HKEY_CURRENT_USER = ^&H80000001>>%scrOut% @echo const HKEY_LOCAL_MACHINE = ^&H80000002>>%scrOut% @echo const Sp = " ">>%scrOut% @echo.>>%scrOut% @echo Dim objWMIService, colItems, objItem, netItems, objnetItem>>%scrOut% @echo Dim oReg>>%scrOut% @echo Dim SZ_DNSSuffix, DWORD_DHCPFlag, MSZ_IPAddress, MSZ_NetMask, MSZ_DefaultGW, SZ_DNServers>>%scrOut% @echo Dim iC, gC>>%scrOut% @echo Dim DNS, DelimFlagCount, DNSNum, DNSCounter, DelimPos, DNSa, DNSb>>%scrOut% @echo.>>%scrOut% @echo Dim obArgs>>%scrOut% @echo Set obArgs = WScript.Arguments>>%scrOut% @echo.>>%scrOut% @rem Done with Generating script header. @goto:eof @rem ---------------------------------------------------------------------- rem@ @rem ---------------------------------------------------------------------- rem@ @rem Generating script body. :genbody @echo Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")>>%scrOut% @echo Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", ^&h30)>>%scrOut% @echo Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}^!\\.\root\default:StdRegProv")>>%scrOut% @echo.>>%scrOut% @echo WScript.Echo " ------------------------------------------------------------------------------">>%scrOut% @echo WScript.Echo " Network Interfaces configuration ">>%scrOut% @echo WScript.Echo " ------------------------------------------------------------------------------">>%scrOut% @echo.>>%scrOut% @echo For Each objItem In colItems>>%scrOut% @echo If (Instr(1, LCASE(objItem.PNPDeviceID), LCASE("PCI\")) = 1) or (Instr(1, LCASE(objItem.PNPDeviceID), LCASE("USB\")) = 1) Then >>%scrOut% @echo Set netItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where Caption = """ ^& objItem.Caption ^& """ ")>>%scrOut% @echo If obArgs.Count = 0 Then>>%scrOut% @echo For Each objnetItem In netItems>>%scrOut% @echo If (objItem.Caption = objnetItem.Caption) Then>>%scrOut% @echo WScript.Echo objItem.NetConnectionID ^& " - Ethernet adapter:">>%scrOut% @echo WScript.Echo>>%scrOut% @echo oReg.GetStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"Domain",SZ_DNSSuffix>>%scrOut% @echo WScript.Echo Sp ^& "DNS-Suffix . . . . . . . . . . . : " ^& SZ_DNSSuffix>>%scrOut% @echo oReg.GetDWORDValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"EnableDHCP",DWORD_DHCPFlag>>%scrOut% @echo If DWORD_DHCPFlag = 0 Then>>%scrOut% @echo WScript.Echo Sp ^& "DHCP Enabled . . . . . . . . . . : No">>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "DHCP Enabled . . . . . . . . . . : Yes">>%scrOut% @echo End If>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"IPAddress",MSZ_IPAddress>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"SubnetMask",MSZ_NetMask>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"DefaultGateway",MSZ_DefaultGW>>%scrOut% @echo.>>%scrOut% @echo For iC = 0 to UBound(MSZ_IPAddress,1)>>%scrOut% @echo If iC ^< 9 Then>>%scrOut% @echo WScript.Echo Sp ^& "IP-Address - " ^& iC ^+ 1 ^& " . . . . . . . . . : " ^& MSZ_IPAddress(iC) ^& "/" ^& MSZ_NetMask(iC)>>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "IP-Address - " ^& iC ^+ 1 ^& " . . . . . . . . . : " ^& MSZ_IPAddress(iC) ^& "/" ^& MSZ_NetMask(iC)>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo.>>%scrOut% @echo oReg.GetStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"NameServer",SZ_DNServers>>%scrOut% @echo DNS = SZ_DNServers>>%scrOut% @echo DelimFlagCount = InStr(1, DNS, ",")>>%scrOut% @echo DNSNum = ^0>>%scrOut% @echo For DNSCounter = 1 to DelimFlagCount ^+ ^1>>%scrOut% @echo DelimPos = InStr(1, DNS, ",")>>%scrOut% @echo If DelimPos ^> 0 Then>>%scrOut% @echo DNSa = Mid(DNS, 1, DelimPos - 1)>>%scrOut% @echo DNSb = Mid(DNS, DelimPos ^+ 1, Len(DNS))>>%scrOut% @echo DNS = DNSb>>%scrOut% @echo DNSNum = DNSNum ^+ ^1>>%scrOut% @echo WScript.Echo Sp ^& "DNS - " ^& DNSNum ^& " . . . . . . . . . . . . . : " ^& DNSa>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo WScript.Echo Sp ^& "DNS - " ^& DNSNum ^+ ^1 ^& " . . . . . . . . . . . . . : " ^& DNS>>%scrOut% @echo.>>%scrOut% @echo WScript.Echo Sp ^& "Gateways:">>%scrOut% @echo For gC = 0 to UBound(MSZ_DefaultGW,1)>>%scrOut% @echo If gC ^< 9 Then>>%scrOut% @echo WScript.Echo Sp ^& "Gateway - " ^& gC ^+ 1 ^& " . . . . . . . . . . . : " ^& MSZ_DefaultGW(gC)>>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "Gateway - " ^& gC ^+ 1 ^& " . . . . . . . . . . : " ^& MSZ_DefaultGW(gC)>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo WScript.Echo>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo Else>>%scrOut% @echo If objItem.NetConnectionID = obArgs.Item(0) Then>>%scrOut% @echo For Each objnetItem In netItems>>%scrOut% @echo WScript.Echo objItem.NetConnectionID ^& " - Ethernet adapter:">>%scrOut% @echo WScript.Echo>>%scrOut% @echo oReg.GetStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"Domain",SZ_DNSSuffix>>%scrOut% @echo WScript.Echo Sp ^& "DNS-Suffix . . . . . . . . . . . : " ^& SZ_DNSSuffix>>%scrOut% @echo oReg.GetDWORDValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"EnableDHCP",DWORD_DHCPFlag>>%scrOut% @echo If DWORD_DHCPFlag = 0 Then>>%scrOut% @echo WScript.Echo Sp ^& "DHCP Enabled . . . . . . . . . . : No">>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "DHCP Enabled . . . . . . . . . . : Yes">>%scrOut% @echo End If>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"IPAddress",MSZ_IPAddress>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"SubnetMask",MSZ_NetMask>>%scrOut% @echo oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"DefaultGateway",MSZ_DefaultGW>>%scrOut% @echo.>>%scrOut% @echo For iC = 0 to UBound(MSZ_IPAddress,1)>>%scrOut% @echo If iC ^< 9 Then>>%scrOut% @echo WScript.Echo Sp ^& "IP-Address - " ^& iC ^+ 1 ^& " . . . . . . . . . : " ^& MSZ_IPAddress(iC) ^& "/" ^& MSZ_NetMask(iC)>>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "IP-Address - " ^& iC ^+ 1 ^& " . . . . . . . . . : " ^& MSZ_IPAddress(iC) ^& "/" ^& MSZ_NetMask(iC)>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo.>>%scrOut% @echo oReg.GetStringValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" ^& objnetItem.SettingID,"NameServer",SZ_DNServers>>%scrOut% @echo DNS = SZ_DNServers>>%scrOut% @echo DelimFlagCount = InStr(1, DNS, ",")>>%scrOut% @echo DNSNum = ^0>>%scrOut% @echo For DNSCounter = 1 to DelimFlagCount ^+ ^1>>%scrOut% @echo DelimPos = InStr(1, DNS, ",")>>%scrOut% @echo If DelimPos ^> 0 Then>>%scrOut% @echo DNSa = Mid(DNS, 1, DelimPos - 1)>>%scrOut% @echo DNSb = Mid(DNS, DelimPos ^+ 1, Len(DNS))>>%scrOut% @echo DNS = DNSb>>%scrOut% @echo DNSNum = DNSNum ^+ ^1>>%scrOut% @echo WScript.Echo Sp ^& "DNS - " ^& DNSNum ^& " . . . . . . . . . . . . . : " ^& DNSa>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo WScript.Echo Sp ^& "DNS - " ^& DNSNum ^+ 1 ^& " . . . . . . . . . . . . . : " ^& DNS>>%scrOut% @echo.>>%scrOut% @echo WScript.Echo Sp ^& "Gateways:">>%scrOut% @echo For gC = 0 to UBound(MSZ_DefaultGW,1)>>%scrOut% @echo If gC ^< 9 Then>>%scrOut% @echo WScript.Echo Sp ^& "Gateway - " ^& gC ^+ 1 ^& " . . . . . . . . . . . : " ^& MSZ_DefaultGW(gC)>>%scrOut% @echo Else>>%scrOut% @echo WScript.Echo Sp ^& "Gateway - " ^& gC ^+ 1 ^& " . . . . . . . . . . : " ^& MSZ_DefaultGW(gC)>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo.>>%scrOut% @echo WScript.Echo>>%scrOut% @echo Next>>%scrOut% @echo End If>>%scrOut% @echo End If>>%scrOut% @echo Set netItems = Nothing>>%scrOut% @echo End If>>%scrOut% @echo Next>>%scrOut% @echo.>>%scrOut% @echo Set oReg = Nothing>>%scrOut% @echo Set colItems = Nothing>>%scrOut% @echo Set objWMIService = Nothing>>%scrOut% @rem Done with Generating script body. @goto:eof @rem ---------------------------------------------------------------------- rem@