Using BGInfo to Display only IPv4 Addresses

I use BGInfo to display a lot of helpful information on my client computers’ desktop. One of these is the IP Address I use to connect to the computer for remote support.  In the past, I’ve used the built in WMI query, but it puts the IPv6 addresses up there as well, and just throws off my formatting. All I need or want is the IPv4 address. I have found a script that can do that.

To catch everyone up on BGInfo, it comes from Microsoft for free, and you can get it here: Microsoft Sysinternals

This page also has all the information you need for setting up and using it, so I’m not going to go into all those details. Now for what you came for. How to display only the IPv4 Address. I just use the vbs script below as a custom field. Simple as that.

strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")

For Each objIPv4 in IPSettings
      For i=LBound(objIPv4.IPAddress) to UBound(objIPv4.IPAddress)
      If InStr(objIPv4.IPAddress(i),":") = 0 Then Echo objIPv4.IPAddress(i)
NEXT
NEXT

If you want just a specific adapter, you can do that as well. Just change the part that says Lenovo Giga Ethernet to whatever the description of your adapter is called.

strComputer = "."
ON ERROR RESUME NEXT
SET objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
SET IPSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True' AND Description = 'Lenovo Giga Ethernet'")

For Each objIPv4 in IPSettings
    For i=LBound(objIPv4.IPAddress) to UBound(objIPv4.IPAddress)
    If InStr(objIPv4.IPAddress(i),":") = 0 Then Echo objIPv4.IPAddress(i)
NEXT

Here is where you find the description:

 

 

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *