473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

In need of a translator!! Listing Subnets in AD

Can anyone help translate this into C#??? It's supposed
to list all subnets in all AD sites (see URL below). I
placed it in a VB class library (one class with
one "Function", WScript.Echo replaced with a string
concat & return statement) and tried to reference it that
way, but I kept getting "object not an instance" errors.
Rather than try to debug that approach in that pea soup
language, I'd rather just rewrite it in C# so I can see
what the H is happening. Is this VB using
DirectoryServices or Management classes?
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get
("configurationNamingContext")

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," &
strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

objSubnetsContainer.Filter = Array("subnet")

Set objHash = CreateObject("Scripting.Dictionary")

For Each objSubnet In objSubnetsContainer

objSubnet.GetInfoEx Array("siteObject"), 0
strSiteObjectDN = objSubnet.Get("siteObject")
strSiteObjectName = Split(Split(strSiteObjectDN, ",")
(0), "=")(1)

If objHash.Exists(strSiteObjectName) Then
objHash(strSiteObjectName) = objHash
(strSiteObjectName) & "," & _
Split
(objSubnet.Name, "=")(1)
Else
objHash.Add strSiteObjectName, Split
(objSubnet.Name, "=")(1)
End If

Next

For Each strKey In objHash.Keys
WScript.Echo strKey & "," & objHash(strKey)
Next

The VB script was taken from this page:

http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/ScriptCenter/network/scrnet24.asp
Nov 15 '05 #1
1 3335
The AD wasn't configured correctly for one thing, so
there WERE no subnets. However, once that was remedied,
the following C# worked

StringBuilder subnets = new StringBuilder();

DirectoryEntry servers = new DirectoryEntry
(@"LDAP://RootDSE");
DirectoryEntry servers2 = new DirectoryEntry
(@"LDAP://cn=Subnets,cn=Sites," + servers.Properties
["configurationNamingContext"].Value );

foreach(DirectoryEntry child in servers2.Children){
subnets.Append(child.Name.Replace("CN=","").Trim()
+ ",");
}

if(subnets.Length > 0)
subnets.Remove(subnets.Length-1, 1);

return subnets.ToString().Split(',');

-----Original Message-----
Can anyone help translate this into C#??? It's supposed
to list all subnets in all AD sites (see URL below). I
placed it in a VB class library (one class with
one "Function", WScript.Echo replaced with a string
concat & return statement) and tried to reference it thatway, but I kept getting "object not an instance" errors.Rather than try to debug that approach in that pea soup
language, I'd rather just rewrite it in C# so I can see
what the H is happening. Is this VB using
DirectoryServices or Management classes?
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get
("configurationNamingContext")

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," &
strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

objSubnetsContainer.Filter = Array("subnet")

Set objHash = CreateObject("Scripting.Dictionary")

For Each objSubnet In objSubnetsContainer

objSubnet.GetInfoEx Array("siteObject"), 0
strSiteObjectDN = objSubnet.Get("siteObject")
strSiteObjectName = Split(Split(strSiteObjectDN, ",")
(0), "=")(1)

If objHash.Exists(strSiteObjectName) Then
objHash(strSiteObjectName) = objHash
(strSiteObjectName) & "," & _
Split
(objSubnet.Name, "=")(1)
Else
objHash.Add strSiteObjectName, Split
(objSubnet.Name, "=")(1)
End If

Next

For Each strKey In objHash.Keys
WScript.Echo strKey & "," & objHash(strKey)
Next

The VB script was taken from this page:

http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/ScriptCenter/network/scrnet24.asp
.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rene Schneider | last post by:
Has anybody ever experimented with something like an ABAP to PHP or JSP translator? Can you think of any elements missing for this purpose from PHP/JSP compared to ABAP? Do you think such a...
0
by: arnie | last post by:
Hi ya all. I am creating a small solution to keep statistics about IP Address accessing a certain system at my workplace. The idea is to be able to group the IP address to a certain subnet so...
23
by: napi | last post by:
Does anybody know if there's any C99 to C89 translator out there, either free or commercial. I searched on Google but couldn't see it so far. Thanks for any tips. Napi
0
by: Shri | last post by:
hi, i need to get subnets of a particular site the code below gives me all the subnets but i need to get subnets of only a particular site
6
by: Patrick Sullivan | last post by:
I want to use this algorithm but can't figure it out, I never used BASIC. I tried translating it but got lost in the gosubs and "for i - 1 to ... nexts". I have figured out that FNU(X) is degree...
4
by: AViS | last post by:
Hi, I am building a language translator, that must convert input from source languages to a language neutral format in XML. This XML must be read by the target language translator and produce the...
0
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: forums_mp | last post by:
Facing a design problem here and I'm not sure how to solve this. The system consists of bi-directional communication between a subject communicating with two (at least for now ) listeners. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.