JSI Tip 9740. How can I set variables equal to a DHCP True/False indicator, IP address, subnet mask, default gateway, MAC address, DNS server address, DHCP server address, and network adapter description on the local computer?

Jerold Schulman

September 14, 2005

2 Min Read
ITPro Today logo

If have scripted DHCPInfo.bat to set environment variables to a DHCP True/False indicator, IP address, subnet mask, default gateway, MAC address, DNS server address, DHCP server address, and network adapter description on the local computer.

The syntax for using DHCPInfo.bat is:

DHCPinfo TrueFalse IPaddress SubNetMask DefGateWay MACaddress DNSsrv DHCPsrv NICdesc

Where:

TrueFalse    is a call directed environment variable that will contain a T if DHCP is enabled or an F if it is not enabled.IPaddress    is a call directed environment variable that will contain the IP address, or NONE.SubNetMask   is a call directed environment variable that will contain the subnet mask, or NONE.DefGateWay   is a call directed environment variable that will contain the default gateway, or NONE.MACaddress   is a call directed environment variable that will contain the MAC address, or NONE.DNSsrv       is a call directed environment variable that will contain the DNS server address, or NONE.DHCPsrv      is a call directed environment variable that will contain the DHCP server address, or NONE.NICdesc      is a call directed environment variable that will contain the network adapter quoted description.

DHCPInfo.bat contains:

@echo offif {%8}=={} @echo Syntax DHCPinfo TrueFalse IPaddress SubNetMask DefGateWay MACaddress DNSsrv DHCPsrv NICdesc&goto :EOFsetlocalif exist "%TEMP%DHCPinfo.vbs" goto doit@echo set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!rootcimv2").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")>"%TEMP%DHCPinfo.vbs"@echo for each IPConfig in IPConfigSet>>"%TEMP%DHCPinfo.vbs"@echo.    wscript.echo 

" ^& IPConfig.DHCPEnabled(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.IPAddress(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.IPSubnet(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.DefaultIPGateway(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.MACAddress(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.DNSServerSearchOrder(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.DHCPServer(i) _>>"%TEMP%DHCPinfo.vbs"@echo. ^&

,

^& IPConfig.Description(i) ^&

">>"%TEMP%DHCPinfo.vbs"@echo.next>>"%TEMP%DHCPinfo.vbs":doitfor /f "Tokens=1-7* Delims=," %%a in ('cscript //nologo "%TEMP%DHCPinfo.vbs"') do ( set a1=%%a set a2=%%b set a3=%%c set a4=%%d set a5=%%e set a6=%%f set a7=%%g set a8=%%h)if /i "%a1%" EQU "True" set a1=T&goto stripset a1=F:stripif %a2% EQU "" (  set a2=NONE  ) ELSE (  set a2=%a2:"=%)if %a3% EQU "" (  set a3=NONE  ) ELSE (  set a3=%a3:"=%)if %a4% EQU "" (  set a4=NONE  ) ELSE (  set a4=%a4:"=%)if %a5% EQU "" (  set a5=NONE  ) ELSE (  set a5=%a5:"=%)if %a6% EQU "" (  set a6=NONE  ) ELSE (  set a6=%a6:"=%)if %a7% EQU "" (  set a7=NONE  ) ELSE (  set a7=%a7:"=%)endlocal&set %1=%a1%&set %2=%a2%&set %3=%a3%&set %4=%a4%&set %5=%a5%&set %6=%a6%&set %7=%a7%&set %8=%a8%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like