Jump to content











Photo
- - - - -

IPconfig


  • Please log in to reply
22 replies to this topic

#1 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 03 October 2008 - 07:25 PM

Does anyone know of command line application that will return the current IP of the system? I can use IPCONFIG but i only wan the IP and not the entire line.

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 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 03 October 2008 - 07:34 PM

I have found a app to do this.. ipa.exe

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 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 05 October 2008 - 12:22 PM

Glad you found a solution.

The other solutions I'd mention involved some coding
http://msdn.microsof...595(VS.85).aspx
http://www.codeproje.../ipaddress.aspx

:confused1:

#4 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 05 October 2008 - 01:04 PM

Why making it more difficult than needed? :confused1:

@ECHO OFF

for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do echo %%A

jaclaz

#5 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 05 October 2008 - 01:36 PM

:cheers: jaclaz :cheers: :cheers: :confused1:, exactly what i was thinking, but were to nice to post. :cheers:

#6 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 05 October 2008 - 02:19 PM

:cheers: jaclaz :cheers: :cheers: :confused1:, exactly what i was thinking, but were to nice to post. :cheers:


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 :cheers:).

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

:cheers:

jaclaz

#7 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 06 October 2008 - 01:39 AM

Jaclaz,

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 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 06 October 2008 - 11:58 AM

Also does not work if you have more than one network card or if you have vmware installed which installs 2 virtual network adapters. Needs to return the first address not the last.

#9 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 06 October 2008 - 12:13 PM

For those cases this works better:

@echo off

for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do (if not X%%AX==XX ( echo %%A & goto :eof ))

:eof


#10 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 07 October 2008 - 01:10 AM

so your saying if multiple nic are used (such as laptop wifi and lan) this other code will work better?

@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 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 07 October 2008 - 03:21 AM

I am saying my tweak will return the first network address not the last. Only you can determine if this better or worse than the original.

#12 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 15 October 2008 - 01:54 PM

Since this is still a IPconfig thread..

Is there a way to display the full config "ipconfig /all" of only one adapter, and not all the adapters on the unit.?

#13 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 15 October 2008 - 04:22 PM

I think i have figured it out.. I used Jaclaz's stuff to figure it out..
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 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 15 October 2008 - 04:35 PM

You need a few more lines, something like this should work (just a base, to be tested and adapted to your needs):
@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 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 15 October 2008 - 04:54 PM

Jaclaz,

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 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 15 October 2008 - 07:06 PM

Try this (again, it's just a draft, no error control):
[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 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 16 October 2008 - 01:23 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..

#18 Lancelot

Lancelot

    Frequent Member

  • .script developer
  • 5013 posts
  • Location:Turkiye/Izmir
  • Interests:*Mechanical stuff and Physics,
    *LiveXP, BartPE, SherpyaXPE,
    *Basketball and Looong Walking,
    *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
    *Girls (Lyric: Girl,...., You will be a womann, Soon)
    *Answering questions for "Meaning of life",
    *Helping people,

    Kung with LiveXP, Fu with Peter :)
  •  
    Turkey

Posted 16 October 2008 - 01:34 PM

Myk3

Try this:

@ECHO OFF

for /f "tokens=2 delims=:" %%A in ('IPCONFIG^|FIND "IP"') do echo %%A

pause

exit


#19 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

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 :confused1:

#20 Lancelot

Lancelot

    Frequent Member

  • .script developer
  • 5013 posts
  • Location:Turkiye/Izmir
  • Interests:*Mechanical stuff and Physics,
    *LiveXP, BartPE, SherpyaXPE,
    *Basketball and Looong Walking,
    *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
    *Girls (Lyric: Girl,...., You will be a womann, Soon)
    *Answering questions for "Meaning of life",
    *Helping people,

    Kung with LiveXP, Fu with Peter :)
  •  
    Turkey

Posted 16 October 2008 - 03:35 PM

@Lancelot
you won't need an EXIT command :cheers:


:confused1:
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
:cheers:

#21 Myk3

Myk3

    Frequent Member

  • Advanced user
  • 108 posts
  •  
    United States

Posted 17 October 2008 - 01:11 PM

Thanks for all the help guys..

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 :confused1:

[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 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 17 October 2008 - 01:20 PM

Happy to know you got it working. :confused1:

jaclaz

#23 Lancelot

Lancelot

    Frequent Member

  • .script developer
  • 5013 posts
  • Location:Turkiye/Izmir
  • Interests:*Mechanical stuff and Physics,
    *LiveXP, BartPE, SherpyaXPE,
    *Basketball and Looong Walking,
    *Buying outwear for my girlf (Reason: Girls are stupid about buying bad stuff to make themselves uglier :))
    *Girls (Lyric: Girl,...., You will be a womann, Soon)
    *Answering questions for "Meaning of life",
    *Helping people,

    Kung with LiveXP, Fu with Peter :)
  •  
    Turkey

Posted 17 October 2008 - 04:40 PM

Myk3

And thanks for sharing :confused1:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users