Solved

Ca we find all static ip's in a domain

Posted on 2006-07-06
13
376 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
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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Accepted Solution

by:
SMFX earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now