Find the active IP in XP, Vista or 7

November 12, 2010 at 05:37:34
Specs: Windows 7, Vista, XP, 2.404 GHz / 3199 MB
I need a batch file to discover the current IP (no need for the wan IP) on a Windows PC running XP, Vista or 7

I already used IPCONFIG method but the result is different if you have multiple NIC on the machines. This was working except from Vista where I have the unused IP coming from the wireless displayed.

Ipconfig /n 3 -i 1 -w 1 | arp -a | find "Interface"

Many thanks for your help,
Best regards,

See More: Find the active IP in XP, Vista or 7

Report •

November 12, 2010 at 10:25:56
I thought I had done this before. Turns out the VBScript was for MAC addresses. So I rewrote it to display connected IP addresses:

Function StdOutGood
  On Error Resume Next
  WScript.StdOut.WriteLine ""
  StdOutGood = Not CBool(Err)
End Function
If Not StdOutGood Then
  CreateObject("WScript.Shell").Run _
    "cmd /c cscript //nologo """ & WScript.ScriptFullName & """ &PAUSE"
End If

Set wmi = GetObject("winmgmts:")
WScript.StdOut.WriteLine "IP Addresses (By Adapter):"
For Each adapter In wmi.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapter " & _
    "WHERE NetConnectionStatus = 2 OR NetConnectionStatus = 9")
  For Each config In adapter.Associators_(, "Win32_NetworkAdapterConfiguration")
    WScript.StdOut.WriteLine config.Description
    WScript.StdOut.WriteLine vbTab & Join(config.IPAddress, vbNewLine & vbTab)
  Next 'config
Next 'adapter

How To Ask Questions The Smart Way

Report •

November 12, 2010 at 11:29:42
Hello Razor2.3,

Many thanks for your reply.

I'm not a programer so I hope my question is not trivial.
I use batch files so how can I use the code you wrote with my scripts?
Best regards,

Report •

November 19, 2010 at 13:01:17
ipconfig /all | findstr /i /c:"ipv4 address"
ipconfig /all | findstr /i /c:"ip addr"

WIll it work for you

Subhash Chandra.

Report •

Related Solutions

November 19, 2010 at 13:10:57
Hello Subhashy,

Many thanks for your reply.
It doesn't work unfortunately as I'm conducting tests on XP, Vista and 7 and the differents OS behave differently espeialy when you have multiple NIC. I just found a small exe that work on all OS I need and who report the same kind of information and I just solved my issue with it. Unfortunately I don't know what has been done in this exe....
The name is "hostinfo.txt" and I have as a result the name, the name fqdm and the active IP. I was mainely interested on the IP.

Best regards,

Report •

Ask Question