connect to AD sites and Services

Started by Orionbelt, March 18, 2014, 10:09:52 AM

Previous topic - Next topic

Orionbelt

Hi all,
   I am trying to move computer to right OU. For right now, i create script to get Default gateway and read ini (which has gatway withs sites) and match the GW and get the site, then move to computer to that site.

Now, i would like to make it more dynamic. I would to get the defaultgateway, connect and match GW in AD Sites service and get site. and the move computer to site.

i didn't find any help doc for winbatch how to connect to AD Sites and get site property out. Can someone here point me to right direction.
here what i have, very simple.
;getting a gateway
strComputerName = "."
objWMIService = GetObject( StrCat( "winmgmts:\\", strComputerName, "\root\CIMV2" ) )

colItems = objWMIService.ExecQuery("SELECT Defaultipgateway FROM Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48)
ForEach objItem In colItems
   strDefaultIPGateway = objItem.DefaultIpGateway
   type = ObjectTypeGet(strDefaultIPGateway)
   If type == "NULL" Then Break
   ;Message("DefaultIPGateway: " , objItem.DefaultIPGateway(0) )

   DefaultGateway = objItem.DefaultIPGateway(0)
Next


;NEED TO CONECT TO AD SItes and match current GW to sites and get site property out.

;moving computer to right ou.
MOVE = dsMoveObj(sTargetPath, sAdsiPath , "CN=%ComputerName%")         ; Moves an ADSI object from one container to another.

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Here is a simple script that might help:

Code (winbatch) Select

AddExtender("WWADS44I.DLL")
sAdsiPath = "LDAP://rootDSE"
sValue = dsGetProperty( sAdsiPath , "configurationNamingContext" )
sSitesContainer = "LDAP://CN=Sites,":sValue
sites = dsFindPath(sSitesContainer, "(objectClass=site)")
AskItemList('Sites', sites, @tab, @unsorted, @single )
Deana F.
Technical Support
Wilson WindowWare Inc.

Orionbelt

thanks Deana for reply,
 
So, question would calcutions of subnet.
If i have ip address of my computer 10.20.25.11

and sites and services, i am pulling 10.228.24.0/23 range, how can I match this range to ip i am getting to get right site. any thoughts?

td

If matching  IPs to a CIDR is your goal then you need to convert the range and the IP to there binary equivalents and then perform a binary operation to test for a match.  At the moment I don't recall any extenders that do this for you but there may be an example in the Tech. DB that illustrates this, assuming you need some help.  Otherwise, we can cook something up for you.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

A starting point:
Code (winbatch) Select
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Accepts an IP Address and a network
;;; CIDR range. Returns true if the
;;; IP Address is part of the CIDR
;;; range.
#DefineFunction IsIpInRange(_Ip, _Net)
 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;; Needs parameter checking!
   ; Convert Ip Address to number
   nIp = 0
   for i = 1 to 4 
      nIp = nIp + (ItemExtract(i, _Ip, ".") << (8*(4-i)))
   next

   ; Get the CIDR notation network address part.
   nNet = 0
   lNet = ItemExtract(1, _Net, "/")
   for i = 1 to 4
      nNet = nNet + (ItemExtract(i, lNet, ".") << (8*(4-i)))
   next

   ; Create a mask from the CIDR range part.
   Bits  = ItemExtract(2, _Net, "/")
   nMask = (~0)<<(32-Bits)
   return (nIp&nMask) == (nNet&nMask)
#endFunction

;Test
bInRange = IsIpInRange("10.20.25.11", "10.228.24.0/23")
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade