static..
Main Topics
Browse All TopicsCan someone help me figure out how to script getting a computer ip address. I know there's several vbscripts out there, but our case is a bit different.
Most of our servers have two nics, both enabled, but only one with a valid static ip address, the other 0.0.0.0. How can I retrieve only the valid ip address and store it. And it varies which nic is the valid one, sometimes nic 1 sometimes nic 2
This would be run locally from the computer.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfig
For Each objAdapter in colAdapters
If objAdapter.IpAddress(i) <> "" Then
MyArray = split(objAdapter.IPAddress
strIPAddress = MyArray(0) & "." & MyArray(1) & "." & MyArray(2) & "."
if debug = 1 Then wscript.echo strIPaddress
End If
Next
I can do this to get the ips of both adapters, but again I need a way to get just the valid one.
Hello,
How about doing string manipulation to look fo an IP in your range?
In this example it is looking for the 1st two octets being 123.456
'---added MyArray(3)
strIPAddress = MyArray(0) & "." & MyArray(1) & "." & MyArray(2) & "." & MyArray(3)
'if debug = 1 Then debug.print strIPaddress
If InStr(strIPAddress, "123.456") Then
wscript.echo strIPAddress
End If
or it could be something like this
strIPAddress = MyArray(0) & "." & MyArray(1) & "." & MyArray(2) & "." & MyArray(3)
'if debug = 1 Then debug.print strIPaddress
If MyArray(0) <> "0" Then
wscript.echo strIPAddress
End If
If this works for you let us know and we can deal with the 'storing the info' part of your question
Hi,
Try this version.....
I have considered the server subnet as 192.0.0.0. If you want you can this in the line below
If Left(StrIP,3) = "192" Then
'SCript starts here...
'Declare Variables
Dim j, NIC1, Nic, StrNic, lngCount, StrIP, i ,objNet,objHost
'If something fails, move on
On Error Resume Next
'Get the Computer's network name
Set objNet=CreateObject("wscri
objHost=objNet.ComputerNam
Wscript.Echo "Analysis of " & objHost & "."
'Get a connection to the WMI NetAdapteConfig object
Set NIC1 = GetObject("winmgmts:").Ins
'For Each of the NICs in the connection
For Each Nic in NIC1
'Get the Adapter Description
StrNIC = Nic.Description
'If IP is enabled on the NIC then let's find out about the NIC
IF Nic.IPEnabled THEN
lngCount=UBound(Nic.IPAddr
For i=0 to lngCount
If i >= 0 Then
wscript.echo "=========================
vbNewLine
wscript.echo StrNic & vbNewLine
StrIP = Nic.IPAddress(i)
If Left(StrIP,3) = "192" Then
WScript.Echo vbTab & "IP Address = " & _
StrIP
WScript.Echo vbTab & "MAC Address = " & _
Nic.MACAddress
Wscript.Echo vbTab & "NIC Service (Short) Name = " & _
Nic.ServiceName
WScript.Echo vbTab & "IP Subnet(s): "
For j = 0 to UBound(Nic.IPSubnet)
Wscript.Echo vbTab & vbTab & Nic.IPSubnet(j)
Next
Wscript.Echo vbTab & "Internet Database Files Path = " & _
Nic.DatabasePath
Wscript.Echo vbTab & "Dead Gateway Detection = " & _
Nic.DeadGWDetectEnabled
Wscript.Echo vbTab & "IP Gateway(s): "
For j=0 to UBound(Nic.DefaultIPGatewa
Wscript.Echo vbTab & vbTab & Nic.DefaultIPGateway(j)
Next
If Nic.DHCPEnabled Then
Wscript.Echo vbTab & "DHCP Assigned IP address = " & _
Nic.DHCPEnabled
Wscript.Echo vbTab & "DHCP Server = " & _
Nic.DHCPServer
End If
Wscript.Echo vbTab & "DNS for WINS Resolution Enabled = " & _
Nic.DNSEnabledforWINSResol
Wscript.Echo vbTab & "DNS Host Name = " & _
Nic.DNSHostName
Wscript.Echo vbTab & "DNS Servers:"
For j=0 to UBound(Nic.DNSServerSearch
Wscript.Echo vbTab & vbTab & Nic.DNSServerSearchOrder(j
Next
Wscript.Echo vbTab & "IP Port Filtering Enabled = " & _
Nic.IPFilterSecurityEnable
If Nic.IPFilterSecurityEnable
WScript.Echo vbTab & "IP Filtering Enabled."
If Nic.IPSecPermitIPProtocols
For j=0 to UBound(Nic.IPSecPermitIPPr
Wscript.Echo vbTab & vbTab & "Protocol: " & _
Nic.IPSecPermitIPProtocols
Next
Else
Wscript.Echo vbTab & vbTab & "No Protocols Filtered"
End If
If Nic.IPSecPermitTCPPorts <> 0 Then
For j=0 to UBound(Nic.IPSecPermitTCPP
WScript.Echo vbTab & vbTab & "TCP Port: " & _
Nic.IPSecPermitTCPPorts(j)
Next
Else
Wscript.Echo vbTab & vbTab & "No TCP Ports Filtered"
End If
If Nic.IPSecPermitUDPPorts <> 0 Then
For j=0 to UBound(Nic.IPSecPermitUDPP
Wscript.Echo vbTab & vbTab & "UDP Port: " & _
Nic.IPSecPermitUDPPorts(j)
Next
Else
WScript.Echo vbTab & vbTab & "No UDP Ports Filtered"
End If
End If
Wscript.Echo vbTab & "LMHOSTS Lookup Enabled = " & _
Nic.WINSEnableLMHostsLooku
Wscript.Echo vbTab & "WINS Lookup File = " & _
Nic.WINSHostLookupFile
Wscript.Echo vbTab & "Primary WINS Server = " & _
Nic.WINSPrimaryServer
Wscript.Echo vbTab & "Secondary WINS Server = " & _
Nic.WINSSecondaryServer
Wscript.Echo vbTab & "WINS Scope ID = " & Nic.WINSScopeID
End If
End If
Next
END IF
Next
Hope this helps.....
This is a script that shows you information per nic, here you can use conditional.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfig
n = 1
WScript.Echo
For Each objAdapter in colAdapters
WScript.Echo "Network Adapter " & n
WScript.Echo "================="
WScript.Echo " Description: " & objAdapter.Description
WScript.Echo " Physical (MAC) address: " & objAdapter.MACAddress
WScript.Echo " Host name: " & objAdapter.DNSHostName
If Not IsNull(objAdapter.IPAddres
For i = 0 To UBound(objAdapter.IPAddres
WScript.Echo " IP address: " & objAdapter.IPAddress(i)
Next
End If
If Not IsNull(objAdapter.IPSubnet
For i = 0 To UBound(objAdapter.IPSubnet
WScript.Echo " Subnet: " & objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultI
For i = 0 To UBound(objAdapter.DefaultI
WScript.Echo " Default gateway: " & _
objAdapter.DefaultIPGatewa
Next
End If
WScript.Echo
WScript.Echo " DNS"
WScript.Echo " ---"
WScript.Echo " DNS servers in search order:"
If Not IsNull(objAdapter.DNSServe
For i = 0 To UBound(objAdapter.DNSServe
WScript.Echo " " & objAdapter.DNSServerSearch
Next
End If
WScript.Echo " DNS domain: " & objAdapter.DNSDomain
If Not IsNull(objAdapter.DNSDomai
For i = 0 To UBound(objAdapter.DNSDomai
WScript.Echo " DNS suffix search list: " & _
objAdapter.DNSDomainSuffix
Next
End If
WScript.Echo
WScript.Echo " DHCP"
WScript.Echo " ----"
WScript.Echo " DHCP enabled: " & objAdapter.DHCPEnabled
WScript.Echo " DHCP server: " & objAdapter.DHCPServer
If Not IsNull(objAdapter.DHCPLeas
utcLeaseObtained = objAdapter.DHCPLeaseObtain
strLeaseObtained = WMIDateStringToDate(utcLea
Else
strLeaseObtained = ""
End If
WScript.Echo " DHCP lease obtained: " & strLeaseObtained
If Not IsNull(objAdapter.DHCPLeas
utcLeaseExpires = objAdapter.DHCPLeaseExpire
strLeaseExpires = WMIDateStringToDate(utcLea
Else
strLeaseExpires = ""
End If
WScript.Echo " DHCP lease expires: " & strLeaseExpires
WScript.Echo
WScript.Echo " WINS"
WScript.Echo " ----"
WScript.Echo " Primary WINS server: " & objAdapter.WINSPrimaryServ
WScript.Echo " Secondary WINS server: " & objAdapter.WINSSecondarySe
WScript.Echo
n = n + 1
Next
Function WMIDateStringToDate(utcDat
WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _
Mid(utcDate, 7, 2) & "/" & _
Left(utcDate, 4) & " " & _
Mid (utcDate, 9, 2) & ":" & _
Mid(utcDate, 11, 2) & ":" & _
Mid(utcDate, 13, 2))
End Function
Business Accounts
Answer for Membership
by: thenonePosted on 2007-10-19 at 13:10:40ID: 20111933
are the clients dhcp?
If so you can look at dns or dhcp scope.