Jump to content

Net View


erifash
 Share

Recommended Posts

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:

Func _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! :)

Link to comment
Share on other sites

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...