Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ca we find all static ip's in a domain

Posted on 2006-07-06
13
Medium Priority
?
384 Views
Last Modified: 2008-03-10
Hi,

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

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 5

Expert Comment

by:ranadastidar
ID: 17056560
arp -a
0
 
LVL 9

Expert Comment

by:binary_1001010
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.
0
 

Expert Comment

by:jacolwireless
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 (192.168.1.2 – 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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:Pber
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   192.168.32.109
PC34 14400 A 192.168.77.71

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
0
 
LVL 6

Expert Comment

by:e_vanheel
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.
0
 
LVL 2

Expert Comment

by:dognamedmoses
ID: 17075718
Turn off your dhcp server and see who complains tomorrow.
0
 
LVL 3

Accepted Solution

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

HTH,
-SMFX



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
                  Err.Clear
            End If
            objRecordSet.MoveNext
      Loop

      ' Clean up.
      objConnection.Close
      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
      Next

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
            Else
                  SysUp = True
                  Exit Function
            End If
      Next
      
      SysUp = FALSE

End Function

0
 
LVL 11

Author Comment

by:bsharath
ID: 17097077
Hi,

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
0
 
LVL 3

Expert Comment

by:SMFX
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.

-SMFX
0
 
LVL 11

Author Comment

by:bsharath
ID: 17097158
Hi,

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

0
 
LVL 3

Expert Comment

by:SMFX
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?

-SMFX
0
 
LVL 11

Author Comment

by:bsharath
ID: 17098109
You are a genius.Great work boss.
0
 
LVL 3

Expert Comment

by:SMFX
ID: 17098358
Glad to help!
-SMFX
0

Featured Post

Independent Software Vendors: 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

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
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.

721 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