Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Ca we find all static ip's in a domain


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

1 Solution
arp -a
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.
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.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

PberSolutions ArchitectCommented:
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 @ /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
Look at

If you are looking to find IP addresses that are alive on your network - both static and DHCP.
Turn off your dhcp server and see who complains tomorrow.
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

bsharathAuthor Commented:

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
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.

bsharathAuthor Commented:

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

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?

bsharathAuthor Commented:
You are a genius.Great work boss.
Glad to help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now