IPconfig
#1
Posted 03 October 2008 - 07:25 PM
Here is the command for IPCONFIG
@ipconfig | find "IP Address"
and the results would be something like
IP Address. . . . . . . . . . . . : 192.168.0.125
I only want the 0.0.0.0 portion and save this as a variable in a batchfile.. if possible.
any thoughts?
Myk3
#2
Posted 03 October 2008 - 07:34 PM
here
here is the clip from the site
IPINFO.EXE simply displays a message box containing one's internet address and internet hostname. For example, right now, it shows me:
204.245.84.28
ppp-028.syracuse-01.ican.net
IPA.EXE and IPN.EXE are console apps which write to STDOUT, the internet address and internet hostname (resp.) of the local computer (the default, no command line arguments) or of an internet hostname or internet address (resp.) specified on the command line. They return 0 upon success, 1 upon error (and write terse error messages to STDERR), and 2 upon writing a brief syntax message (to STDERR). Their syntaxes are simple:
ipa [[/?|-?] | hostname]
ipn [[/?|-?] | ipaddress]
When they succeed, IPA.EXE and IPN.EXE produce very simple STDOUT... only the requested information (an IP address or a hostname). This is by design ... in order to make their output suitable for use in batch files and other scripts.
All three are in IPINFO.ZIP. Get IPINFO.ZIP via anonymous FTP . A friend tells me they also work correctly under Windows95.
NT tip: Here's a little known way to perform command output substitution with NT's CMD.EXE. Suppose you want to set the environment variable %HOSTNAME% to the string returned by IPN.EXE; use:
for /f %x in ('ipn.exe') do set hostname=%x
[Use %%x in batch files.]
#3
Posted 05 October 2008 - 12:22 PM
The other solutions I'd mention involved some coding
http://msdn.microsof...595(VS.85).aspx
http://www.codeproje.../ipaddress.aspx
#4
Posted 05 October 2008 - 01:04 PM
@ECHO OFF for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do echo %%A
jaclaz
#5
Posted 05 October 2008 - 01:36 PM
#6
Posted 05 October 2008 - 02:19 PM
jaclaz , exactly what i was thinking, but were to nice to post.
I see it a bit differently, everyone is perfectly free to pursue his/her attempts to re-invent the wheel (or hot water) but they should KNOW it has been already invented, and possibly invent an improved one (like hotter hot water or rounder wheels ).
http://www.boot-land...?...c=2037&st=7
Informing people about this undeniable "historical" fact is not "nice" or "nasty", it's just a little help into avoiding exceeding in complexities:
Everything should be made as simple as possible, but not simpler.
BTW, did you know that actually automotive wheels are being re-invented?
Here is the TWEEL (Tire+WhEEL):
http://en.wikipedia.org/wiki/Tweel
http://www.michelinm...271/kw=MCHtweel
http://www.michelinm...086/kw=MCHtweel
jaclaz
#7
Posted 06 October 2008 - 01:39 AM
Thanks for the help.. Works like a charm.. I am going to use your way since it does not require a extra application to be used..
I did modify it slightly however..
Myk3
for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do [b]set ip[/b]=%%A
I am using this to set a network based TV tuner to stream to the appropriate pc.. and it works like a charm.. Thanks..
#8
Posted 06 October 2008 - 11:58 AM
#9
Posted 06 October 2008 - 12:13 PM
@echo off for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do (if not X%%AX==XX ( echo %%A & goto :eof )) :eof
#10
Posted 07 October 2008 - 01:10 AM
@echo off for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do (if not X%%AX==XX ( echo %%A & goto :eof )) :eof
Myk3
#11
Posted 07 October 2008 - 03:21 AM
#12
Posted 15 October 2008 - 01:54 PM
Is there a way to display the full config "ipconfig /all" of only one adapter, and not all the adapters on the unit.?
#13
Posted 15 October 2008 - 04:22 PM
for /f "tokens=1 delims=" %A in ('IPCONFIG /ALL^|FIND "DNS Servers"') do echo %A
edit: This will only display the first DNS Server not the 2nd.. Is there a way to display both?
#14
Posted 15 October 2008 - 04:35 PM
@ECHO OFFSET Whattofind=%1SETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONSET /A DCounter=0FOR /f "tokens=2 delims=:" %%A in ('IPCONFIG /ALL ^|FIND "Descr"') do (REM ECHO %%ASET /A DCounter=!DCounter!+1SET Nic_Descr_!DCounter!=%%A)SET /A ICounter=0FOR /f "tokens=2 delims=:" %%A in ('IPCONFIG /ALL ^|FIND "IP."') do (REM ECHO %%ASet /A ICounter=!ICounter!+1SET Nic_IP_!ICounter!=%%A)FOR %%A in ( 1 2 3 4 5 6 7 8 9) DO (IF DEFINED Nic_Descr_%%A SET Nic_Descr_%%A=%%A:!Nic_Descr_%%A:~0,30!:!Nic_IP_%%A!FOR /F "tokens=1,2,3 delims=:" %%B IN ('ECHO !Nic_Descr_%%A!^|FIND /I "%Whattofind%"') DO ECHO %%C : %%D)This accepts one parameter that has to be part of the description string for the NIC.jaclazP.S.: Please note that in the second FOR loop there is a full stop in the search string FIND "IP."' , that I need on Italian OS, for English it should be removed.
#15
Posted 15 October 2008 - 04:54 PM
The main thing I need the both the DNS servers listed.. I can get the first one but not the 2nd .. Is there a way to do this?
#16
Posted 15 October 2008 - 07:06 PM
[codebox] @ECHO OFF FOR /f "tokens=2 delims=:" %%A in ('IPCONFIG /ALL ^|FIND "DNS"^|FIND "."') do ( CALL :ShoWDNS %%A ) FOR /f "tokens=1 delims=" %%A in ('IPCONFIG /ALL ^|FIND /V ":"^|FIND /V "Windows"') do ( CALL :ShoWDNS %%A ) goto :eof :ShowDNS SET DNS=%* IF DEFINED DNS ECHO %DNS%
goto :eof
[/codebox]
jaclaz
#17
Posted 16 October 2008 - 01:23 PM
#18
Posted 16 October 2008 - 01:34 PM
Try this:
@ECHO OFF for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do echo %%A pause exit
#19
Posted 16 October 2008 - 03:18 PM
This does work, but it closes the cmd prompt as soon as it runs.. I have tried adding a pause and have tried to add this to my batch and it didn't work either..
It depends where you added the PAUSE, it goes here:
PAUSE
goto :eof
:ShowDNS
And of course, since as said, it's just a draft, you should OPEN a CMD prompt windows and test it from there.
jaclaz
@Lancelot
you won't need an EXIT command
#20
Posted 16 October 2008 - 03:35 PM
@Lancelot
you won't need an EXIT command
an old habit of preventing unwanted stop (in my cases mostly unwanted, it can be wanted too), when starting a .cmd file by using another .cmd file
#21
Posted 17 October 2008 - 01:11 PM
Here is what I have and it works... Thanks again.. This is just so I can see and change my current DNS settings for when I use my ssh tunnel from work
[codebox]@echo off color 1f :start cls ECHO Current DNS Settings echo. FOR /f "tokens=2 delims=:" %%A in ('IPCONFIG /ALL ^|FIND "DNS"^|FIND "."') do ( CALL :ShoWDNS %%A ) FOR /f "tokens=1 delims=" %%A in ('IPCONFIG /ALL ^|FIND /V ":"^|FIND /V "Windows"') do ( CALL :ShoWDNS %%A ) Echo. echo. ECHO What DNS would you like to use? set /p choice= DHCP (1) or OpenDNS (2)? [1/2] : if '%choice%'=='' goto error if '%choice%'=='1' goto DHCP if '%choice%'=='2' goto OPEN goto error REM Change DNS Server to Local DNS Server :DHCP netsh interface ip set dns name="Wireless Network Connection 2" dhcp netsh interface ip add dns name="Wireless Network Connection 2" dhcp goto exit REM Change DNS Server to OpenDNS servers.. :OPEN netsh interface ip set dns name="Wireless Network Connection 2" source=static addr=208.67.222.222 Netsh interface ip add dns name="Wireless Network Connection 2" addr=208.67.220.220 goto exit :error cls ECHO You have entered an incorrect option.. Valid options are 1 or 2. pause goto start :exit cls echo New DNS Settings echo. FOR /f "tokens=2 delims=:" %%A in ('IPCONFIG /ALL ^|FIND "DNS"^|FIND "."') do ( CALL :ShoWDNS %%A ) FOR /f "tokens=1 delims=" %%A in ('IPCONFIG /ALL ^|FIND /V ":"^|FIND /V "Windows"') do (
CALL :ShoWDNS %%A
)
pause
goto :eof
:ShowDNS
SET DNS=%*
IF DEFINED DNS ECHO %DNS%
goto :eof[/codebox]
#22
Posted 17 October 2008 - 01:20 PM
jaclaz
#23
Posted 17 October 2008 - 04:40 PM
And thanks for sharing
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users