Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Capture the IP address

346 views
Skip to first unread message

Tom a

unread,
Dec 26, 2011, 4:40:28 PM12/26/11
to
I need a script that can capture the IP address in to a variable.
OS=XP or Win7, but language can be 5 different so it needs to be a bit
clever.
That is why I am asking you guys here :-)
I can not just do an ipconfig ^| findstr /c:"IP Address" as it might
not be case that the word IP Address is there.
I was thinking about something along the lines of capturing the output
of ping %computername% as it should always be the third parameter I
think ..
But I can not really get it to work, so some help would be appreciated.

It would also be good if the tag number could be captures (on Dell
PC's).

Any ideas?

Best regards
Tom

--

Tom a

unread,
Dec 26, 2011, 5:52:31 PM12/26/11
to
> I need a script that can capture the IP address in to a variable.
> OS=XP or Win7, but language can be 5 different so it needs to be a bit
> clever.
> That is why I am asking you guys here :-)
> I can not just do an ipconfig ^| findstr /c:"IP Address" as it might
..
>
> It would also be good if the tag number could be captures (on Dell
> PC's).


Best attempt so far is:
for /f "tokens=3 delims= " %%i in ('ping -4 -n 1 %computername% ^|
findstr "TTL" ') do set ip1=%%i
Seems to be working on both XP and Win7, but could be refined I'm sure.

To capture the serial I have looked at: wmic get bios serial number
It seems to be working fine on Win7 but it seems like it needs to be
installed the first time it is run on XP which is not so ideal..

Suggestions are stil more than welcome on both issues
/Tom
--

foxidrive

unread,
Dec 26, 2011, 9:20:18 PM12/26/11
to
On 27/12/2011 09:52, Tom wrote:
>> I need a script that can capture the IP address in to a variable.
>> OS=XP or Win7, but language can be 5 different so it needs to be a bit
>> clever.
>> That is why I am asking you guys here :-)
>> I can not just do an ipconfig ^| findstr /c:"IP Address" as it might
> ..
>>
>> It would also be good if the tag number could be captures (on Dell
>> PC's).
>
>
> Best attempt so far is:
> for /f "tokens=3 delims= " %%i in ('ping -4 -n 1 %computername% ^|
> findstr "TTL" ') do set ip1=%%i
> Seems to be working on both XP and Win7, but could be refined I'm sure.

This removes the : at the end too.


@echo off
for /f "tokens=3 delims=: " %%a in (
'ping -n 1 %computername% ^|findstr "TTL=" '
) do set ip1=%%a


> To capture the serial I have looked at: wmic get bios serial number
> It seems to be working fine on Win7 but it seems like it needs to be
> installed the first time it is run on XP which is not so ideal..
>
> Suggestions are stil more than welcome on both issues
> /Tom

wmic is not available on XP Home unless you install it.


Does this contain what you need? It takes a while to generate the file.

"c:\Program Files\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report file.txt



--
Regards,
Mic

Bob

unread,
Dec 27, 2011, 9:24:56 AM12/27/11
to
Tom typed the following on 12/26/2011 5:52 PM:
Greetings Tom,

My DELL has a 7 character alpha/numeric string stored in a file
name sysinfo.dat which is a plain text file. The contents of my
file looks like this: (Actual tag number/serial number edited)

[ServiceTag]
ServiceTag=x1x1x1x

So I can retrieve the Service Tag/serial number with,

::All lines indented 3 spaces. Tested
::Using Microsoft Windows XP [Version 5.1.2600]
@echo off
setlocal
for /f "tokens=1 delims=" %%b in ('type sysinfo.dat ^|find /i
"ServiceTag"') do set tag=%%b
set tag=%tag:~11,7%
echo %tag%
pause
endlocal


Tom a

unread,
Dec 28, 2011, 11:54:59 AM12/28/11
to
> [ServiceTag]
> ServiceTag=x1x1x1x
>
> So I can retrieve the Service Tag/serial number with,
>
> ::All lines indented 3 spaces. Tested
> ::Using Microsoft Windows XP [Version 5.1.2600]
> @echo off
> setlocal
> for /f "tokens=1 delims=" %%b in ('type sysinfo.dat ^|find /i
> "ServiceTag"') do set tag=%%b set tag=%tag:~11,7%
> echo %tag%
> pause
> endlocal

--
I can not find the sysinfo file on my systems, but I have found some
other logfiles containing the tag number that I might be able to parse
the same way.

So now I have two options I can work on.

Btw. any suggestions on getting the output from the "wmic bios get
serialnumber" command in to a variable in a better way than this?:
for /F %i IN ('wmic bios get serialnumber') do set ss=%i

/Tom

foxidrive

unread,
Dec 28, 2011, 12:10:16 PM12/28/11
to
On 29/12/2011 03:54, Tom wrote:
> Btw. any suggestions on getting the output from the "wmic bios get
> serialnumber" command in to a variable in a better way than this?:
> for /F %i IN ('wmic bios get serialnumber') do set ss=%i

Apart from using a batch file you mean? It seems fine, except that some machines don't have a serial number. This is from my machine.


===[paste]===
C:\>wmic bios get serialnumber
SerialNumber



C:\>
===[paste]===

So you will have to add logic to test if the variable is not a number or is set to "SerialNumber"


--
Regards,
Mic

Bob

unread,
Dec 28, 2011, 4:47:29 PM12/28/11
to
Tom typed the following on 12/28/2011 11:54 AM:
>> [ServiceTag]
>> ServiceTag=x1x1x1x
>>
>> So I can retrieve the Service Tag/serial number with,
>>
>> ::All lines indented 3 spaces. Tested
>> ::Using Microsoft Windows XP [Version 5.1.2600]
>> @echo off
>> setlocal
>> for /f "tokens=1 delims=" %%b in ('type sysinfo.dat ^|find /i
>> "ServiceTag"') do set tag=%%b set tag=%tag:~11,7%
>> echo %tag%
>> pause
>> endlocal
>

Tom,
Your for /f statement works for me. The Serial Number and Service
Tag on my DELL are the same alpha numeric string. Not much more I
can do other than type HAPPY NEW YEAR!

Later.

Tom a

unread,
Dec 29, 2011, 1:47:53 PM12/29/11
to

> Your for /f statement works for me. The Serial Number and Service
> Tag on my DELL are the same alpha numeric string. Not much more I
> can do other than type HAPPY NEW YEAR!
>
> Later.

The challenge I have is that the command gives me 3 lines of ourput and
the last one is just blank. This is what I get:

C:\>for /F %i in ('wmic bios get serialnumber') do set tag=%i
C:\>set tag=SerialNumber
C:\>set tag=JS1335J
:\>set tag=
C:\>
So %tag% ends up with no value in it..

Btw: Happy new year to you too .. :-)
/Tom
--

billious

unread,
Dec 29, 2011, 2:32:07 PM12/29/11
to

"Tom" <super_otc(a)yahoo.com> wrote in message
news:4efcb5d9$0$284$1472...@news.sunsite.dk...
...umber') do if not "%i"=="" set tag=%i


Bob

unread,
Dec 29, 2011, 4:59:05 PM12/29/11
to
Tom typed the following on 12/29/2011 1:47 PM:
Tom,
Going by your command line example then you are getting the expected
results from the final line of set tag=

Try the batch file below.

@echo off
setlocal
for /f %%i in ('wmic bios get serialnumber') do set tag=%%i
echo Serialnumber=%tag%
pause
endlocal

If that does not work on your DELL then I'm stumped.

Later.

Tom a

unread,
Dec 30, 2011, 5:31:22 PM12/30/11
to
Bob wrote:
>
> @echo off
> setlocal
> for /f %%i in ('wmic bios get serialnumber') do set tag=%%i
> echo Serialnumber=%tag%
> pause
> endlocal
>
> If that does not work on your DELL then I'm stumped.
>
> Later.

It is still not working for me ..

I have also tried the following. First to set cnt to 1 followed by:
for /F %i in ('wmic bios get name') do set tag%cnt%=%i&set /A cnt+=1

I would then expect to be able to refer to %tag1% %tag2% and so on, but
this was what happened...

C:\>set cnt=1

C:\>for /F %i in ('wmic bios get name') do set tag%cnt%=%i&set /A cnt+=1

C:\>set tag1=Name & set /A cnt+=1
2
C:\>set tag1=Phoenix & set /A cnt+=1
3
& set /A cnt+=1
4
C:\>
So I am not able to get the second value out, like in this case Phoenix

Regards
Tom
--

Tom a

unread,
Dec 30, 2011, 5:36:22 PM12/30/11
to
billious wrote:

> do if not "%i"=="" set tag=%i

Good idea but no cigar this time:
This is what happened:

C:\>for /F %i in ('wmic bios get name') do if not "%i"=="" set tag=%i

C:\>if not "Name" == "" set tag=Name

C:\>if not "Phoenix" == "" set tag=Phoenix

== "" set tag=

C:\>echo %tag%
ECHO is on.

Thanks
Tom
--

Tom a

unread,
Dec 30, 2011, 5:59:22 PM12/30/11
to
Sorry! it depends on where you smoke your cigar.
It did work on XP, but not on the Win7 PC I used when first testing it.
Seems like they react differently
/Tom
--

Tom a

unread,
Dec 30, 2011, 6:01:10 PM12/30/11
to
Please note that I did the test on Win7 not XP.
They seems to react different in this case.
/Tom

--

billious

unread,
Dec 31, 2011, 12:20:28 AM12/31/11
to

"Tom" <super_otc(a)yahoo.com> wrote in message
news:4efe4249$0$288$1472...@news.sunsite.dk...
Hmm - will admit my solution was air-code as I use XP/H which doesn't have
WMIC.

I'd theorise that WMIC is one of those annoying utilities that does not use
CRLF combinations conventionally - the odd display characteristic you report
(with the 'if not' missing) makes me suspicious here. For some utilities,
the report is

Line with spacesCRdata to overtype spacesCRLF

or similar. Spitting the output out to a file and examining it with a
hex-viewer may reveal something. I believe MORE may be pressed into use to
make corrections...

wmic ... |more >file

And of course the XP and W7 versions would be different, so no doubt
someone's played with the code...


Dr J R Stockton

unread,
Jan 1, 2012, 2:20:38 PM1/1/12
to
In alt.msdos.batch.nt message <eoadnVL2-q8CBmPTnZ2dnUVZ_hmdnZ2d@westnet.
com.au>, Sat, 31 Dec 2011 13:20:28, billious <billio...@hotmail.com>
posted:

>
>I'd theorise that WMIC is one of those annoying utilities that does not use
>CRLF combinations conventionally -

Win XP sp3 CMD.EXE, using MiniTrue (16)

prompt> wmic bios get name | mt /h

shows :

000000: 4e 61 6d 65 20 20 20 20 20 20 20 20 20 20 20 20 ¦ Name
000010: 20 20 20 20 20 0d 0d 0a 44 65 66 61 75 6c 74 20 ¦ ???Default
000020: 53 79 73 74 65 6d 20 42 49 4f 53 20 20 0d 0d 0a ¦ System BIOS ???
000030: 0d 0a ¦ ??

Note the 0d 0d 0d, twice.

Pipe it through my utility COLS, argument 1-, via sig line 3, which ignores any
LF after a CR and treats CR as NL, outputting it as CRLF, gives :

000000: 4e 61 6d 65 20 20 20 20 20 20 20 20 20 20 20 20 ¦ Name
000010: 20 20 20 20 20 0d 0a 0d 0a 44 65 66 61 75 6c 74 ¦ ????Default
000020: 20 53 79 73 74 65 6d 20 42 49 4f 53 20 20 0d 0a ¦ System BIOS ??
000030: 0d 0a 0d 0a ¦ ????

with respectable newlines.

And from the Help for MiniTrue (32),

Example 14 - Normalizing line ends in a DOS text file

mtr file.txt \r\n = \r\n \n = \r\n \r = \z

But piping through DOS MORE does no good.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Petr Laznovsky

unread,
Jan 5, 2012, 8:56:41 AM1/5/12
to
This can be language and Win version independent

untested

for /f %a in ('netsh interface ip sh config') do echo %a | findstr /R
"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/[0-9]*"

L.

Petr Laznovsky

unread,
Jan 5, 2012, 1:15:42 PM1/5/12
to
fixed version, all in one line

@echo off & (for /f "tokens=1-2 delims=:(" %a in ('netsh interface ip sh
config') do echo %b | findstr /R
"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/[0-9]*") & echo on

slash for some reason cannot work as delimiter to cut netmask size

L.

foxidrive

unread,
Jan 5, 2012, 7:48:37 PM1/5/12
to

It doesn't seem to work here, I get no output.

What information are you trying to parse? When I use 'netsh interface ip sh config' the only IP address listed is for my Virtualbox Network and the DNS address for my Local area connection.
--
Regards,
Mic

Petr Laznovsky

unread,
Jan 6, 2012, 5:15:24 AM1/6/12
to
On 6.1.2012 1:48, foxidrive wrote:
>
> It doesn't seem to work here, I get no output.
>
> What information are you trying to parse? When I use 'netsh interface ip sh config' the only IP address listed is for my Virtualbox Network and the DNS address for my Local area connection.
>
>


This is my output of "netsh interface ip sh config" but I have all IP
addresses configured MANUALY (no DHCP) and this can be the reason....


Configuration for interface "WLAN0"
DHCP enabled: No
IP Address: 10.12.32.8
Subnet Prefix: 10.12.32.0/25 (mask
255.255.255.128)
InterfaceMetric: 30
Statically Configured DNS Servers: None
Register with which suffix: Primary only
Statically Configured WINS Servers: None

Configuration for interface "??????"
DHCP enabled: No
IP Address: 192.168.137.1
Subnet Prefix: 192.168.137.0/24 (mask
255.255.255.0)
InterfaceMetric: 20
Statically Configured DNS Servers: None
Register with which suffix: Primary only
Statically Configured WINS Servers: None

Configuration for interface "ETH0"
DHCP enabled: No
IP Address: 10.12.32.20
Subnet Prefix: 10.12.32.0/25 (mask
255.255.255.128)
IP Address: 192.168.2.125
Subnet Prefix: 192.168.2.0/24 (mask
255.255.255.0)
IP Address: 192.168.5.120
Subnet Prefix: 192.168.5.0/24 (mask
255.255.255.0)
IP Address: 192.168.123.200
Subnet Prefix: 192.168.123.0/24 (mask
255.255.255.0)
Default Gateway: 10.12.32.1
Gateway Metric: 1
InterfaceMetric: 20
Statically Configured DNS Servers: 10.12.49.251
Register with which suffix: None
Statically Configured WINS Servers: None

Configuration for interface "Loopback Pseudo-Interface 1"
DHCP enabled: No
IP Address: 127.0.0.1
Subnet Prefix: 127.0.0.0/8 (mask 255.0.0.0)
InterfaceMetric: 50
Statically Configured DNS Servers: None
Register with which suffix: Primary only
Statically Configured WINS Servers: None

foxidrive

unread,
Jan 6, 2012, 6:11:18 AM1/6/12
to
This is all I get:


Configuration for interface "Local Area Connection 13"
DHCP enabled: Yes
InterfaceMetric: 0
DNS servers configured through DHCP: 192.168.1.254
WINS servers configured through DHCP: None
Register with which suffix: Primary only

Configuration for interface "VirtualBox Host-Only Network"
DHCP enabled: No
IP Address: 192.168.56.1
SubnetMask: 255.255.255.0
InterfaceMetric: 0
Statically Configured DNS Servers: None
Statically Configured WINS Servers: None
Register with which suffix: Primary only

Configuration for interface "Local Area Connection 10"
DHCP enabled: Yes
InterfaceMetric: 0
DNS servers configured through DHCP: None
WINS servers configured through DHCP: None
Register with which suffix: Primary only






--
Regards,
Mic

Petr Laznovsky

unread,
Jan 6, 2012, 7:08:07 AM1/6/12
to
Than sorry for confusing, it is for sure DHCP issue.

L.

Petr Laznovsky

unread,
Jan 6, 2012, 7:43:37 AM1/6/12
to
On 6.1.2012 12:11, foxidrive wrote:
What about this? For me it`s work but I have currently not DHCP server
availible, thus I cannot confirm with DHCP enabled.


@echo off & setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%a in ('
netsh interface ipv4 sh ipaddr
') do (
call :parse %%a
)
goto end
::
:parse
if not "%1"=="" (
echo %1 | findstr /R "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
shift
goto :parse
)
GOTO:EOF
::
:end

foxidrive

unread,
Jan 6, 2012, 8:01:17 AM1/6/12
to
On 6/01/2012 23:43, Petr Laznovsky wrote:

> What about this? For me it`s work but I have currently not DHCP server
> availible, thus I cannot confirm with DHCP enabled.
>
>
> @echo off & setlocal ENABLEDELAYEDEXPANSION
> for /f "tokens=*" %%a in ('
> netsh interface ipv4 sh ipaddr
> ') do (
> call :parse %%a
> )
> goto end
> ::
> :parse
> if not "%1"=="" (
> echo %1 | findstr /R "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
> shift
> goto :parse
> )
> GOTO:EOF
> ::
> :end


I got no output, and the reason is below in XP Pro SP3


D:\>netsh interface ipv4 sh ipaddr
The following command was not found: interface ipv4 sh ipaddr.



--
Regards,
Mic

foxidrive

unread,
Jan 6, 2012, 8:34:49 AM1/6/12
to
With some trialling I found that this works to show the IP address.

D:\>netsh interface ip show ipaddress

MIB-II IP Address Entry
IP Address Mask BC Fmt Reasm Sz Interface
--------------- --------------- ------ -------- -----------------------
127.0.0.1 255.0.0.0 1 65535 Loopback
192.168.1.103 255.255.255.0 1 65535 Local Area Connection 13
192.168.56.1 255.255.255.0 1 65535 VirtualBox Host-Only Network



It requires the Routing and Remote Access service to be running, which I also had disabled for security reasons.

There has to be a way to determine which IP address is right from the list, but if you ping the machine name then it will also reveal the IP address.


@echo off
for /f "tokens=3 delims=: " %%b in (
'ping %computername% -n 1 ^|find /i "reply"'
) do set ip=%%b
echo "%ip%"
pause








--
Regards,
Mic

tonysathre

unread,
Jan 10, 2012, 2:13:30 PM1/10/12
to
Here is a one-liner that will get the IP address of the first
interface on your system. Tested on Windows 7 x64 and Windows XP SP3:
This should also work on Windows 9x systems.

for /f "tokens=3 delims=:" %i in ('arp -a ^| findstr /n /l ":" ^| find
"2:"') do @for /f %z in ('echo %i') do @echo %z

Tony

tonysathre

unread,
Jan 10, 2012, 2:14:36 PM1/10/12
to

foxidrive

unread,
Jan 10, 2012, 10:49:38 PM1/10/12
to
This works on XP SP3 and Win 7 x32

for /f "tokens=2" %i in ('arp -a ^| find ":"') do echo %i


In Win98SE arp -a returns "No ARP Entries found"


--
Regards,
Mic

tonysathre

unread,
Jan 11, 2012, 10:46:49 AM1/11/12
to
That was how I did it originally, but on any system with multiple
network interfaces, that will return the IP address for all interfaces
and not just the first, or "primary" interface. That's why in my
findstr I used /n to number them and then parsed out the first one as
being the primary interface.

Tony

foxidrive

unread,
Jan 11, 2012, 12:10:19 PM1/11/12
to
That sounds fair. I did note that in my Win98SE VM it had two ethernet adapters (0 and 1) and only the second one was used (1) but that may be a curiosity - it's an old install converted to a VM.




--
Regards,
Mic

Petr Laznovsky

unread,
Jan 19, 2012, 10:23:53 AM1/19/12
to
And what about this? This give me all ip addresses from all interfaces
in the system and should be language independent.

@echo off & setlocal ENABLEDELAYEDEXPANSION
set semaphore=0
for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]* > NUL
if not "!errorlevel!"=="1" (
set /a semaphore=!semaphore!+1
if "!semaphore!"=="1" set ipaddr=%%a
if "!semaphore!"=="2" (
set semaphore=0
set ipaddr=!ipaddr:~1!
echo !ipaddr!
)
)
)

foxidrive

unread,
Jan 19, 2012, 11:59:57 AM1/19/12
to
On 20/01/2012 02:23, Petr Laznovsky wrote:

> And what about this? This give me all ip addresses from all interfaces
> in the system and should be language independent.
>
> @echo off & setlocal ENABLEDELAYEDEXPANSION
> set semaphore=0
> for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
> echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]* > NUL
> if not "!errorlevel!"=="1" (
> set /a semaphore=!semaphore!+1
> if "!semaphore!"=="1" set ipaddr=%%a
> if "!semaphore!"=="2" (
> set semaphore=0
> set ipaddr=!ipaddr:~1!
> echo !ipaddr!
> )
> )
> )


Your code gives me the IP address and default gateway.

I did post a simple method of getting the IP address of %computername% using ping - it seems the easiest method for the original query, which was to get the IP address of the machine.



See here for my ipconfig info.

Windows IP Configuration




Ethernet adapter Local Area Connection 13:


Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.103
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.254


Ethernet adapter VirtualBox Host-Only Network:


Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :


Ethernet adapter Local Area Connection 10:


Media State . . . . . . . . . . . : Media disconnected



--
Mic



Petr Laznovsky

unread,
Jan 20, 2012, 5:04:21 AM1/20/12
to
On 19.1.2012 17:59, foxidrive wrote:
> On 20/01/2012 02:23, Petr Laznovsky wrote:
>
>> And what about this? This give me all ip addresses from all interfaces
>> in the system and should be language independent.
>>
>> @echo off& setlocal ENABLEDELAYEDEXPANSION
>> set semaphore=0
>> for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
>> echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*> NUL
>> if not "!errorlevel!"=="1" (
>> set /a semaphore=!semaphore!+1
>> if "!semaphore!"=="1" set ipaddr=%%a
>> if "!semaphore!"=="2" (
>> set semaphore=0
>> set ipaddr=!ipaddr:~1!
>> echo !ipaddr!
>> )
>> )
>> )
>
>
> Your code gives me the IP address and default gateway.

What is strange, for me work on your ipconfig output fine, but maybe
some unwanted changes when copy from news client. Could you send me your
output of "ipconfig > ipconfig.txt" command in the attached file?

>
> I did post a simple method of getting the IP address of %computername% using ping - it seems the easiest method for the original query, which was to get the IP address of the machine.
>

Forget to tell you: This code failed if IPv6 is enabled on the system.
Windows take precedence on IPv6 if both versions of protocol are
enabled. On my machine:

C:\scripts>ping %computername% -n 1

Pinging xxx.yyy [fe80::e59c:7dd6:af04:3aa5%11] with 32 bytes of data:
Reply from fe80::e59c:7dd6:af04:3aa5%11: time<1ms

Ping statistics for fe80::e59c:7dd6:af04:3aa5%11:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms


>
> See here for my ipconfig info.
>
> Windows IP Configuration
>
>
>
>
> Ethernet adapter Local Area Connection 13:
>
>
> Connection-specific DNS Suffix . :
> IP Address. . . . . . . . . . . . : 192.168.1.103
> Subnet Mask . . . . . . . . . . . : 255.255.255.0
> Default Gateway . . . . . . . . . : 192.168.1.254
>
>
> Ethernet adapter VirtualBox Host-Only Network:
>
>
> Connection-specific DNS Suffix . :
> IP Address. . . . . . . . . . . . : 192.168.56.1
> Subnet Mask . . . . . . . . . . . : 255.255.255.0
> Default Gateway . . . . . . . . . :
>
>
> Ethernet adapter Local Area Connection 10:
>
>
> Media State . . . . . . . . . . . : Media disconnected

With slight modification, this can work also on your system.

@echo off & setlocal ENABLEDELAYEDEXPANSION
set semaphore=0
for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]* > NUL
if not "!errorlevel!"=="1" (
set /a semaphore=!semaphore!+1
if "!semaphore!"=="1" set ipaddr=%%a
if "!semaphore!"=="2" (
set semaphore=0
set ipaddr=!ipaddr:~1!
echo !ipaddr!
)
) else (
set semaphore=0
)
)



My ipconfig:




Windows IP Configuration


Wireless LAN adapter WLAN0:

Connection-specific DNS Suffix . : xxx.yyy
Link-local IPv6 Address . . . . . : fe80::fca2:94a8:4a30:7d58%14
IPv4 Address. . . . . . . . . . . : 10.12.32.8
Subnet Mask . . . . . . . . . . . : 255.255.255.128
Default Gateway . . . . . . . . . :

Ethernet adapter ??????:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Ethernet adapter ETH0:

Connection-specific DNS Suffix . : xxx.yyy
Link-local IPv6 Address . . . . . : fe80::e59c:7dd6:af04:3aa5%11
IPv4 Address. . . . . . . . . . . : 10.12.32.20
Subnet Mask . . . . . . . . . . . : 255.255.255.128
IPv4 Address. . . . . . . . . . . : 192.168.2.125
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.5.120
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.123.200
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.12.32.1

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2001:0:5ef5:79fd:3801:78f8:b193:9834
Link-local IPv6 Address . . . . . : fe80::3801:78f8:b193:9834%64
Default Gateway . . . . . . . . . : ::

Tunnel adapter 6TO4 Adapter:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter isatap.{EBA1B91C-E994-452E-B44A-EEA557EF4780}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Local Area Connection* 53:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Reusable Microsoft 6To4 Adapter:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter isatap.pankrac.czf:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : xxx.yyy

foxidrive

unread,
Jan 20, 2012, 5:52:39 AM1/20/12
to
On 20/01/2012 21:04, Petr Laznovsky wrote:
> On 19.1.2012 17:59, foxidrive wrote:

> With slight modification, this can work also on your system.
>
> @echo off & setlocal ENABLEDELAYEDEXPANSION
> set semaphore=0
> for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
> echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]* > NUL
> if not "!errorlevel!"=="1" (
> set /a semaphore=!semaphore!+1
> if "!semaphore!"=="1" set ipaddr=%%a
> if "!semaphore!"=="2" (
> set semaphore=0
> set ipaddr=!ipaddr:~1!
> echo !ipaddr!
> )
> ) else (
> set semaphore=0
> )
> )
>

Yes, it did work.

IPV6, oh great. They put percent signs in them. :)

>
> My ipconfig:
>
>
>
>
> Windows IP Configuration
>
>
> Wireless LAN adapter WLAN0:
>
> Connection-specific DNS Suffix . : xxx.yyy
> Link-local IPv6 Address . . . . . : fe80::fca2:94a8:4a30:7d58%14
> IPv4 Address. . . . . . . . . . . : 10.12.32.8
> Subnet Mask . . . . . . . . . . . : 255.255.255.128
> Default Gateway . . . . . . . . . :


I'm to old to learn IPv6, and all the escaping with carets and percent signs for no reason, in recent posts. ;)


Maybe I'll give up batch files for Lent. *wink*



--
Mic

Petr Laznovsky

unread,
Jan 20, 2012, 7:33:36 AM1/20/12
to
> IPV6, oh great. They put percent signs in them. :)

RFC-4007


11. Textual Representation

As already mentioned, to specify an IPv6 non-global address without
ambiguity, an intended scope zone should be specified as well. As a
common notation to specify the scope zone, an implementation SHOULD
support the following format:

<address>%<zone_id>

where

<address> is a literal IPv6 address,

<zone_id> is a string identifying the zone of the address, and

`%' is a delimiter character to distinguish between <address> and
<zone_id>.


foxidrive

unread,
Jan 21, 2012, 12:05:36 AM1/21/12
to
Thanks. At least there's only one of them.


--
Mic

tonysathre

unread,
Jan 24, 2012, 10:58:18 AM1/24/12
to
On Jan 20, 11:05 pm, foxidrive <foxidr...@gotcha.woohoo.invalid>
wrote:
If IPv6 is causing problems, you can force ping to use IPv4 addresses
only.

ping -4 %computername%

A problem I noticed with this approach is that on my test system, I
have a loopback adapter installed, which causing ping to return an
APIPA address instead of my actual LAN IP. Has the OP's problem been
solved? I'm curious which approach worked for him.

Tony

tonysathre

unread,
Jan 24, 2012, 11:15:17 AM1/24/12
to
After looking a bit closer it looks like which ever adapter is listed
first in IPCONFIG, gets used when pinging %computername%. Below is my
IPCONFIG.


Windows IP Configuration

Host Name . . . . . . . . . . . . : hostname
Primary Dns Suffix . . . . . . . : xxx.yyy
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : xxx.yyy

Ethernet adapter Local Area Connection 4:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Loopback Adapter #2
Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::b11a:3498:1f48:ee1b
%22(Preferred)
Autoconfiguration IPv4 Address. . : 169.254.238.27(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
DHCPv6 IAID . . . . . . . . . . . : 402784332
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-16-0E-5F-0E-1C-C1-
DE-5D-CD-DE

DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Local Area Connection 3:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Loopback Adapter
Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::c125:9a3e:1fad:239b
%20(Preferred)
IPv4 Address. . . . . . . . . . . : 172.16.2.243(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.248.0
Default Gateway . . . . . . . . . : 0.0.0.0
DHCPv6 IAID . . . . . . . . . . . : 302121036
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-16-0E-5F-0E-1C-C1-
DE-5D-CD-DE

DNS Servers . . . . . . . . . . . : 172.16.0.32
172.16.0.40
NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : xxx.yyy
Description . . . . . . . . . . . : Broadcom NetXtreme Gigabit
Ethernet
Physical Address. . . . . . . . . : 1C-C1-DE-5D-CD-DE
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::78d5:a42a:
6dbc:fef5%12(Preferred)
IPv4 Address. . . . . . . . . . . : 172.16.2.13(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.248.0
Lease Obtained. . . . . . . . . . : Wednesday, January 18, 2012
10:49:00 AM
Lease Expires . . . . . . . . . . : Wednesday, February 01, 2012
10:49:01 AM
Default Gateway . . . . . . . . . : 172.16.0.1
DHCP Server . . . . . . . . . . . : 172.16.0.32
DHCPv6 IAID . . . . . . . . . . . : 253542878
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-16-0E-5F-0E-1C-C1-
DE-5D-CD-DE

DNS Servers . . . . . . . . . . . : 172.16.0.32
172.16.0.40
Primary WINS Server . . . . . . . : 172.16.0.32
NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter isatap.{57A6814D-8995-4CBC-BB8F-3FD96F9D6C6A}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Local Area Connection* 11:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Teredo Tunneling
Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{3E0DC927-6AF8-4F67-8971-0C0FD60F0FB2}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.xxx.yyy:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : xxx.yyy
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Petr Laznovsky

unread,
Jan 31, 2012, 5:05:15 PM1/31/12
to
In my version, IPv6 do not cause any problems. It list all IPv4
addresses in the system:

@echo off & setlocal ENABLEDELAYEDEXPANSION
set semaphore=0
for /f "tokens=2 delims=:" %%a in ('ipconfig') do (
echo %%a | findstr /R [0-9]*\.[0-9]*\.[0-9]*\.[0-9]* > NUL
if not "!errorlevel!"=="1" (
set /a semaphore=!semaphore!+1
if "!semaphore!"=="1" set ipaddr=%%a
if "!semaphore!"=="2" (
set semaphore=0
set ipaddr=!ipaddr:~1!
echo !ipaddr!
)
) else (
set semaphore=0
)
)

The possible problem of your solution is, if the "-4" switch may not be
available on the prior versions of OS. On my WXP SP3 it did work
(although the "-4" switch is not documented with "ping /?") but in prior
SP???

L.

0 new messages