Page 2 of 2 <12
Topic Options
#197171 - 2009-12-16 05:30 PM Re: Registry Scanning with List [Re: Tesdall]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
 Originally Posted By: Tesdall
My mistake on where to inject the correct code.
If you're talking about placement of the ping() UDF, it's irrelevant. kix32 parses the script for Function blocks before running.

FWIW, I tend to place UDFs at the bottom of the script, keeping my own code at the top.

Top
#197172 - 2009-12-16 06:39 PM Re: Registry Scanning with List [Re: Tesdall]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
Here is the "final" code that appears to work fairly well.

 Code:
Break on

function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
	if $GetIP
		dim $ip, $ipfile, $
		$ipfile = @scriptdir + '\ip.txt'
		shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
		+ '"ping ' + $Computer1 + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
		$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
		if $ip
			$Ping = $ip
		else
			$Ping = 'Bad IP address ' + $Computer + '!'
		endif
		exit 0
	else
		if $TimeOut
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		else
			for $c = 0 to $LoopCount
				shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
				if @error = 0
					$Ping = 1
					exit 0
				endif
			next
		endif
		$Ping = 0
	endif
endfunction

; Declare variables to prevent scope creep
Dim $InFile, $OutFile			; file names for input and output
Dim $Computer				; computer name, from input file
Dim $Rc					; return-code catcher
Dim $Version				; Version data from Computer

$Rc = SetOption('NoVarsInStings', 'On')

$OutFile = ('c:\test\version.txt')
$InFile  = ('c:\test\ie8.txt')

; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
  'Failed to open ' $InFile ' - aborting!' ?
  Exit 1
EndIf

; same for the output file
If Open( 2 , $OutFile, 5) <> 0
  'Failed to open ' $OutFile ' - aborting!' ?
  Exit 1
EndIf

; Read the first line, then loop until EOD (End Of Data) error
$Computer = ReadLine(1)
While Not @ERROR

  'Computer: ' $Computer ?		; display the current computer

  ; Only read the registry if the computer is online
  If Ping($Computer, 0)
    $Version = Readvalue('\\' + $Computer + '\HKLM\SOFTWARE\Microsoft\Internet Explorer', 'Version')
  Else
    $Version = 'PC Not Online'		; no ping response
  EndIf

  ; If the registry data is blank, provide appropriate message
  $Version = IIf($Version, $Version, 'Invalid data from PC')

  'Version: ' $Version ?		Display version

  $Rc = WriteLine(2, $Version + ',' + $Computer + @CRLF)

  $Computer = ReadLine(1)

Loop

$Rc = Close(1)
$Rc = Close(2)


I will try to help out anyone with this script if they need me to.


Edited by Tesdall (2009-12-16 06:40 PM)
_________________________
Where ever you go, there you are.

Top
#197173 - 2009-12-16 09:12 PM Re: Registry Scanning with List [Re: eriqjaffe]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
 Originally Posted By: eriqjaffe
ping() is not an in-built function of KiXtart. You'll need to get the UDF here and paste the code into your script.

This is an outdated version and requires two parameters. Use this one
 Code:
;;
;;======================================================================
;;
;;FUNCTION       ping()
;;
;;ACTION         ping - Pings a host
;;
;;AUTHOR         Glenn Barnas
;;
;;VERSION	 2.0 - 2007/10/20 - WHS version
;;		 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to 
;;			return values and IP's
;;
;;SYNTAX         ping(host, [Flag], [Wait])
;;
;;PARAMETERS     host - name of host to ping
;;               FLAG - if negative, returns IP Address
;;                      if >0, specifies number of tries (default is 1)
;;               Wait - optional ping timeout value
;;               
;;
;;REMARKS        ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS        FLAG >= 0: returns 1 if host is reachable, 0 if not
;;               FLAG <  0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES   OS Commands Ping & Find
;;
;;TESTED WITH    NT4, W2K, WXP
;;
;;EXAMPLES       Ping('hostname')       ; returns Success/Failure
;;               Ping('hostname',-1)    ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)

  Dim $_oExec				; WSH Object
  Dim $_Tries				; # of times to ping
  Dim $_Timeout				; Ping timeout value
  Dim $_Response			; Response Flag
  Dim $_Line				; Line returned from command string
  Dim $_Cmd				; first part of command string
  Dim $_Count				; current ping count

  $_Flag    = Val($_Flag)		; determine what to do
  $_Wait    = Val($_Wait)		; 
  $_Tries   = 1				; one ping
  $_Timeout = 1000			; 1 second timeout

  ; set timeout if Wait is non-zero
  If $_Wait > 0
    $_Timeout = $_Wait
  EndIf

  If $_FLAG > 0        ; Multiple pings - return on first reply
    $_Tries = $_FLAG
  EndIf

  ; Ping the host $_Tries times, but only until a response is received
  $_Count = 0

  ; search for reply from host during PING
  $_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host 
  If $_Flag < 0
    $_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
  Else
    $_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
  EndIf
  Do
    $_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
    If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
    $_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
    $_Response = IIf($_Line, 1, 0)
    If $_Response
      $_Count = $_Tries
    EndIf
    $_Count = $_Count + 1
    If $_Count <  $_Tries Sleep 0.25 EndIf
  Until $_Count >= $_Tries

  ; If FLAG >= 0, return success/failure - otherwise return IP address
  If $_FLAG >= 0
    $Ping = $_Response
  Else
    If Not $_Response
      $Ping = '0.0.0.0'
    Else
      ; In this mode we return the IP address - we should have the HOSTNAME
      ; handle the 'duh' factor for times when we get the IP address instead!
      If InStr($_Line,'[') > 0
        $Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
      Else
        $Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
      EndIf
    EndIf
  EndIf

  Exit Not $_Response       ; set the error code

EndFunction

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 2141 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.069 seconds in which 0.047 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