Page 1 of 1 1
Topic Options
#183314 - 2007-12-05 10:07 PM Looking for a Good way to generate a Host list
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
I currently have a static file of Host names for all the clients in my network.

I would like to Generate a Host list of Client computers in my network, and I am not sure what the best way to approach this is, so I don't have to manually update the static host file.

I can see that this will be beneficial when i need to run scripts that require me to input the host name.

I have thought about trying to read active directory, or using nmap. When I have tried using Nmap I ran into the problem of having to filter the output string of data i needed down to the host name.

Thanks for the input.

Indigo

Top
#183315 - 2007-12-05 10:10 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Opps forgot,

I would like to sort the clients by windows xp because i only want to apply update scripts to the xp clients.

Thanks

Indgio

Top
#183318 - 2007-12-05 10:45 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
How many computers do you have to maintain?
Top
#183319 - 2007-12-05 10:58 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could use the COMNetview() UDF. Do a check on all found computers to see if they are online with the Ping() UDF and if they are check the OS type by reading the registry with the ReadValue() function. If the OS is XP write them using the WriteLine() function to a file if they are not XP write it to an other file.

Somethig like this.

 Code:
Break on

$rc = Open(1,"c:\xpsystems.txt",5)
$rc = Open(2,"c:\nonxpsystems.txt",5)
$rc = Open(3,"c:\notonline.txt",5)

$computers = COMNetView(domainname)

For Each $computer in $computers
	$online = Ping($computer,0,4,2500)
	If $online = "1"
		$winver = ReadValue("\\" + $computer + "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
		If $winver = "Microsoft Windows XP"
			$rc = WriteLine(1,$computer + ";" + $winver + @CRLF)
		Else
			$rc = WriteLine(2,$computer + ";" + $winver + @CRLF)
		EndIf
	Else
		$rc = WriteLine(3,$computer + " is not online." + @CRLF)
	EndIf
Next

$rc = Close(1)
$rc = Close(2)
$rc = Close(3)


You should call or include these UDF's in the code above.
UDF Library » COMNetView() - Enumerate all computers in your domain
UDF Library » Ping() - checks for reply , or returns ip-address of remote host
KiXtart FAQ & How to's » How to use UDFs
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#183320 - 2007-12-05 11:17 PM Re: Looking for a Good way to generate a Host list [Re: Mart]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Thanks for the quick reply \:\)

I have to maintian roughly 100 systems.

Top
#183321 - 2007-12-05 11:19 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You don't have a Windows Domain with DNS server?
Top
#183322 - 2007-12-05 11:21 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Is there a reason you have to use a hosts file?
_________________________
(... better days ahead)

Top
#183326 - 2007-12-06 03:44 AM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
DHCP,DNS,WINS are much better ways to manage addressing.
Top
#183344 - 2007-12-06 02:12 PM Re: Looking for a Good way to generate a Host list [Re: NTDOC]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Mart,

Thanks man that program was amazing. It worked like a charm! I tell ya that's how i want to be. Just be able to drop down the code off my head.

Allen,

Nope, I didn't know how to track the computers on my network when i started making scripts to run against them, so the idea that came to me was to generate a host file.

NTDOC,

Yes i use dhcp, dns, but no wins.

Is there any tools i can use to parse dhcp? etc?

Thanks everyone for your help thus far.

Top
#183346 - 2007-12-06 03:31 PM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I use KiXtart to access DNS and DHCP information, but to be honest it doesn't get you much further than what you have.

The technique that you choose really depends on how you are going to use the information.

Here is a simple example of how to query AD, kludged from examples found around the board - in your case you can use the operatingSystem property to select the computers (XP) to act on.
 Code:
BREAK on
 
$objConnection = CreateObject("ADODB.Connection")
$objCommand =   CreateObject("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = 
   "SELECT Name,OperatingSystem FROM " 
   + "'LDAP://"
   + GetObject("LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")).distinguishedName
   + "'"
   + " WHERE objectCategory='computer'"
 
$objCommand.Properties("Page Size").Value = 100
$objCommand.Properties("Search Scope").Value = 2
$objCommand.Properties("Cache Results").Value = (not 1)
 
$objRecordSet = $objCommand.Execute()
$objRecordSet.MoveFirst
while not $objRecordSet.EOF
   $objRecordSet.Fields("Name").Value+" "+$objRecordSet.Fields("operatingSystem").Value+@CRLF
   $objRecordSet.MoveNext
Loop
 
Exit 0

Top
#183351 - 2007-12-06 05:18 PM Re: Looking for a Good way to generate a Host list [Re: Richard H.]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Anyone have a good link i could use to read up on the Obj commands?

Thanks for the Script example Richard.

Top
#183367 - 2007-12-07 09:51 AM Re: Looking for a Good way to generate a Host list [Re: Indigoseth]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: Indigoseth
Anyone have a good link i could use to read up on the Obj commands?


That's a big subject.

Basic object support in a language like KiXtart is very simple. It doesn't really do a lot from your perspective apart from provide access to the objects and their method and properties.

In this regard it is exactly the same as any other language with "COM automation" object support, so you can read up on (say) using objects in VB to get the basic idea.

There are some major deficiences in object support with KiXtart, which means that you simply cannot use some features. Off the top of my head:
  • Events are not supported at all. There is a kind of work-around using event sinks, but I've never got it working properly.
  • Enumerations are not automatically populated or easily derived. You need to find them in documentation or by using an object browser and add them manually to your code.
  • Pass-by-reference variables are not supported.
  • Certain ways of coding properties in objects do not work with KiXtart, so you don't get the values returned. I'm not clear on the rules myself, but basically until you try it you won't know if it is going to work or not.
  • KiXtart does not support parameters when creating objects


As regards the objects themselves, there is no single good resource for them all. The Microsoft objects (Windows, AD, DHCP, DNS, WSUS etc) are all documented on the MS sites. Third party objects (like AutoIT) are documented by the supplier, though the quality and availability of the documentation varies hugely.

Once you become familiar with objects you will be able to use object browsing tools to identify capabilities, but often it is simpler to Google with a few choice terms to find example code that you can convert to KiXtart semantics.

Top
#183406 - 2007-12-07 09:05 PM Re: Looking for a Good way to generate a Host list [Re: Richard H.]
Indigoseth Offline
Getting the hang of it

Registered: 2007-11-16
Posts: 78
Thanks for the heads up!

Indigo

I will do some digging around.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.16 seconds in which 0.121 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org