erifash Posted July 30, 2005 Posted July 30, 2005 I'm not sure if this has been done before, it probably has, but here is a quick way to get an array of all the computers on a network: expandcollapse popupFunc _NetView($sNetwork = "") Local $iPID = Run(@ComSpec & " /c net view" & _Test($sNetwork = "", "", " /NETWORK:" & $sNetwork), @SystemDir, @SW_HIDE, 2), $sLine = "" While @error <> -1 $sLine = $sLine & StdoutRead($iPID) Wend If not StringInStr($sLine, "The command completed successfully.") Then setError(1) Return "" EndIf Local $iComps = _StringFindOccurances($sLine, "\\"), $sRet = "|" For $i = 1 to $iComps $sRet = $sRet & _StringParse($sLine, "\\", " ", $i) & "|" Next Return StringSplit(StringTrimLeft(StringTrimRight(StringReplace($sRet, "|", "|\\"), 3), 1), "|") EndFunc Func _StringParse($sz_str, $sz_before, $sz_after, $i_occurance = 0) Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1) If $i_occurance < 0 or $i_occurance > $sz_sp1[0] Then SetError(1) Return "" EndIf Local $sz_sp2 = _Test($i_occurance = 0, StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1), StringSplit($sz_sp1[$i_occurance + 1], $sz_after, 1)) Return $sz_sp2[1] EndFunc ;==>_StringParse() Func _Test($b_Test, $v_True = 1, $v_False = 0) If $b_Test Then Return $v_True Return $v_False EndFunc Func _StringFindOccurances($sStr1, $sStr2) For $i = 1 to StringLen($sStr1) If not StringInStr($sStr1, $sStr2, 1, $i) Then ExitLoop Next Return $i - 1 EndFunc I had to modify my string parsing function to accept occurances, which I have been wanting to do for a long time... I really hope that you like this function! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
Helge Posted July 31, 2005 Posted July 31, 2005 (edited) What about also making a function which retreives all the workgroups in the network ?Edit : Too hot here.. Edited July 31, 2005 by Helge
erifash Posted August 1, 2005 Author Posted August 1, 2005 I don't know... I have never had a need for that but I guess anyone could make that if they tried. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
Tys Posted August 2, 2005 Posted August 2, 2005 Nice Scriptlet, two problems occurred to me when I tried that the same way via net view: Computers that was recently switched on do not appear in the list for about 15 (rough estimation) and already dead computers appear for max 20 minutes. For the latter, a ping ($workstation,50) does it. For not apperaing computers the solution could be a pingsweep with nmap or similar. Regards, Tys
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now