Go Premium for a chance to win a PS4. Enter to Win


Ca we find all static ip's in a domain

Posted on 2006-07-06
Medium Priority
Last Modified: 2008-03-10

Is there a code or script to find all Static ip's in the domain.We have a DHCP server too.

Question by:bsharath

Expert Comment

ID: 17056560
arp -a

Expert Comment

ID: 17056605
run the DHCP on your dhcp server, your should see a tab or folder called " DHCP leased" , it will show you which are static, which are dynamic.

Expert Comment

ID: 17057553
Well hoping that you have things setup right your DHCP server is going to be providing leases to a range of I.P. address' for example ( – 100) these can be omited from the static ip's as you never want to assign a static ip in your dhcp range unless you like to have ip conflicts every once an a while.

there is no remote way to tell if the ip address is a static or dynamic ip its only the client that is privy to that information, and that can be found out how ranadastidar sugested, arp -a. however because we know the range of the dhcp server we can assume that any ip outside the specified range is static.

You can find what ip’s are occupied in your static range (that is if you don’t know) by doing a ping scan. This will send out pings to the ip’s in question and look for responces. Note that this will only work if your computers don’t have a software based firewall blocking icmp network traffic.

Hope that helps.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 26

Expert Comment

ID: 17057797
This might work...

Do you have Microsoft DNS?   If so and if you maintain your static IP's in DNS manually you can do a dump of dns and filter out all the DDNS records which would be all your DHCP'd clients in this situation.  It's not the most elequent way of doing it...

dnscmd yourdnsservername /enumrecords your.zone.com @ /Type A >c:\a.txt

This will dump all the A records from DNS.  Now all the output of the file will have items like this:

PC44 [Aging:3554644] 900 A
PC34 14400 A

Any items with the Aging would signify a DDNS records and would most likely be a DDNS record.  I say most likely because you can still have static IP on a client and still have them register in DNS.  A static DNS record in DNS can also be aged.  But if you manually enter your computers with static IP's in DNS manually, this will be very accurate.

So you can load it up in excel or some other editor and filter out or search/delete the records that have Aging in them and the ones that are remaining would be static IP's

Expert Comment

ID: 17063588
Look at http://www.solarwinds.net/Toolsets.htm.

If you are looking to find IP addresses that are alive on your network - both static and DHCP.

Expert Comment

ID: 17075718
Turn off your dhcp server and see who complains tomorrow.

Accepted Solution

SMFX earned 2000 total points
ID: 17096988
The code below is VBScript that uses WMI to connect to the all the computers in your domain and display if DHCP is enabled and their IP(s) in a tab seperated format.  You can cut & paste it into a notepad, save it as a .VBS file, then run it from the command prompt using cscript.


CONST COL_SEP = "      "

EnumComputers ""

Sub EnumComputers(strDomain)

      Dim objRootDSE, strDNSDomain, objConnection, objCommand, strQuery
      Dim objRecordSet, strCompName

      If strDomain = "" Then
            ' Determine DNS domain name from RootDSE object.
            Set objRootDSE = GetObject("LDAP://RootDSE")
            strDomain = objRootDSE.Get("defaultNamingContext")
      End If

      ' Use ADO to search Active Directory for all computers.
      Set objCommand = CreateObject("ADODB.Command")
      Set objConnection = CreateObject("ADODB.Connection")
      objConnection.Provider = "ADsDSOObject"
      objConnection.Open "Active Directory Provider"
      objCommand.ActiveConnection = objConnection

      strQuery = "<LDAP://" & strDomain _
        & ">;(objectCategory=computer);" _
        & "sAMAccountName;subtree"

      objCommand.CommandText = strQuery
      objCommand.Properties("Page Size") = 500
      objCommand.Properties("Timeout") = 45
      objCommand.Properties("Cache Results") = False

      Set objRecordSet = objCommand.Execute

      ' Enumerate computer objects with server operating systems.
      Do Until objRecordSet.EOF
            strCompName = objRecordSet.Fields("sAMAccountName")
            strCompName = Left(strCompName,Len(strCompName)-1)  'Remove the trailing "$" on computer accounts from the name
            If SysUp(strCompName) Then
                  DisplayDHCP strCompName
            End If
            If Err.number <> 0 Then
                  Wscript.Echo strCompName + COL_SEP + "ERROR: " + Err.number + COL_SEP + Err.Description
            End If

      ' Clean up.
      Set objRootDSE = Nothing
      Set objCommand = Nothing
      Set objConnection = Nothing
      Set objRecordSet = Nothing

End Sub

Sub DisplayDHCP(sComputer)

      'WScript.Echo sComputer            'For debugging purposes
      Set objWMIService = GetObject( _
          "winmgmts:\\" & sComputer & "\root\cimv2")
      Set IPConfigSet = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration ")
      For Each IPConfig in IPConfigSet
            Output = ""
            If Not IsNull(IPConfig.IPAddress) Then
                  Output = Output & IPConfig.DNSHostName
                  If (IPConfig.FUllDNSRegistrationEnabled) Then
                      Output = Output & "." & IPConfig.DNSDomain
                  End If
                  Output = Output & COL_SEP & IPConfig.DHCPEnabled
                  Output = Output & COL_SEP & Join(IPConfig.IPAddress,",")
            End If
            If Output<>"" THen WScript.Echo Output

End Sub

Function SysUp(sComputer)

      Dim strComputer

      strComputer = "."

      Set objWMIService = GetObject(_
            "winmgmts:\\" & strComputer & "\root\cimv2")
      Set colPings = objWMIService.ExecQuery _
            ("Select * From Win32_PingStatus where Address = '" + sComputer + "'")

      For Each objStatus in colPings
            If IsNull(objStatus.StatusCode) _
                  or objStatus.StatusCode<>0 Then
                  SysUp = FALSE
                  SysUp = True
                  Exit Function
            End If
      SysUp = FALSE

End Function

LVL 11

Author Comment

ID: 17097077

i get this error

C:\>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\test.vbs(61, 6) (null): 0x80041003

Expert Comment

ID: 17097096
That looks like an access is denied error.  Most likely the account you ran the script under is not an admin of the remote machine you attempted to connect to.  If you remove the tick mark commenting the line out just before it:
      WScript.Echo sComputer            'For debugging purposes
It will show you what machine it was trying to connect to.

LVL 11

Author Comment

ID: 17097158

This worked but after scanning 20 pc's it gives and error

C:\test.vbs(61, 6) Microsoft VBScript runtime error: Permission denied: 'GetObject'

I have logged in as a domain admin only


Expert Comment

ID: 17097184
that is a problem with WMI and VBScripts.  When it doesn't connect right, it bombs out.  You can try adding "On Error Resume Next" as the first line and it should try to bounce over it.

And you're sure that the Domain Admin is a member of the local admins on the 21st machine?

LVL 11

Author Comment

ID: 17098109
You are a genius.Great work boss.

Expert Comment

ID: 17098358
Glad to help!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question