Jump to content

Network List


Ghost21
 Share

Recommended Posts

Ok so I'm have a brain Fart... And this is some ugly code but it works.. KINDA

I would just like to read one Line at a time if thats possible...

Second thought I could funnel to to a txt file but that just takes to long..

I would like to keep the data the starts with \\

then count over how ever number of characters for the whole name until it hits white space

then if it finds that it reads

"The command completed successfully."

then exit

..............................................

#include <Constants.au3>

#include <String.au3>

$foo = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

While 1

$line = StdoutRead($foo,1)

$data = Stringmid($line, 1,2)

if $data = "\" Then

$line = StdoutRead($foo,12)

$Line = StringTrimLeft($line,1)

If @error Then ExitLoop

msgbox(0,"",$line)

Else

If @error Then ExitLoop

EndIf

Wend

Exit

Link to comment
Share on other sites

Ok so I'm have a brain Fart... And this is some ugly code but it works.. KINDA

I would just like to read one Line at a time if thats possible...

Second thought I could funnel to to a txt file but that just takes to long..

I would like to keep the data the starts with \\

then count over how ever number of characters for the whole name until it hits white space

then if it finds that it reads

"The command completed successfully."

then exit

..............................................

#include <Constants.au3>

#include <String.au3>

$foo = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

While 1

$line = StdoutRead($foo,1)

$data = Stringmid($line, 1,2)

if $data = "\" Then

$line = StdoutRead($foo,12)

$Line = StringTrimLeft($line,1)

If @error Then ExitLoop

msgbox(0,"",$line)

Else

If @error Then ExitLoop

EndIf

Wend

Exit

:) help....

Link to comment
Share on other sites

Don't Really see what you are trying to accomplish but for sure your Else statement is wrong because you're checking of @Error again

I think this is closer to what you want

While 1

$line = StdoutRead($foo,1)
$data = Stringmid($line, 1,2)
if $data = "\" Then
$line = StdoutRead($foo,12)
$Line = StringTrimLeft($line,1)
If @error Then
ExitLoop
Else
msgbox(0,"",$line)
EndIf
Wend

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Don't Really see what you are trying to accomplish but for sure your Else statement is wrong because you're checking of @Error again

I think this is closer to what you want

While 1

$line = StdoutRead($foo,1)
$data = Stringmid($line, 1,2)
if $data = "\" Then
$line = StdoutRead($foo,12)
$Line = StringTrimLeft($line,1)
If @error Then
ExitLoop
Else
msgbox(0,"",$line)
EndIf
Endif
Wend

What I was trying to do is scan the current domain for a list of PCs and at the endof the list when it says "The command completed successfully." Exit the loop.

That's the just of it...

Link to comment
Share on other sites

What I was trying to do is scan the current domain for a list of PCs and at the endof the list when it says "The command completed successfully." Exit the loop.

That's the just of it...

If what I gave you didn't work then post your actual code and we'll get it fixed.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If what I gave you didn't work then post your actual code and we'll get it fixed.

$get = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

While 1

$line = StdoutRead($get)

If @error Then ExitLoop

msgbox(0,"Active PC's",$line) <--- Would like to filter this show when you run it. It only shows active PC'S not all the other crap..

;~ $PC = $line

;~ Call("addlist",$PC) <--- Shoots it to a SQL DATABASE

Wend

msgbox(0,"Finished Active PC List",$line)

Exit

Link to comment
Share on other sites

$get = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

While 1

$line = StdoutRead($get)

If @error Then ExitLoop

msgbox(0,"Active PC's",$line) <--- Would like to filter this show when you run it. It only shows active PC'S not all the other crap..

;~ $PC = $line

;~ Call("addlist",$PC) <--- Shoots it to a SQL DATABASE

Wend

msgbox(0,"Finished Active PC List",$line)

Exit

Okay, the problem you are going to have with this is that there is no way to pause $Get. So by the time you respond to a message box the Run() will probably have exited. I think I can fix that but leave it with me for a while (busy today) unless someone else comes up with it first.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This works but just use the parts you need.

$Line = ""
$get = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, 2)
While $get
    $Line &= StdoutRead($get)
    If @error Then ExitLoop
Wend
$Line = StringSplit(StringStripCR($Line), @LF)
$Out = ""
For $I = 1 To $Line[0]
    If StringLeft($Line[$I], 2) = "\\" then
        $Line[$I] = StringTrimLeft($Line[$I], 2)
        $Out &= StringLeft($Line[$I], StringInStr($Line[$I], Chr(32))) & @CRLF
        MsgBox(0, "Computer", StringLeft($Line[$I], StringInStr($Line[$I], Chr(32))))
    EndIf
Next
MsgBox(0, "Finished", "Finished parsing computer list" & @CRLF & @CRLF & $Out)
Exit

$Out is probably not required for your purposes and replace the MsgBox in the If statement to what ever function you want to perform.

Edit: Spelling cops got me again!!!

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This works but just use the parts you need.

$Line = ""
$get = Run(@ComSpec & " /c net view", @SystemDir, @SW_HIDE, 2)
While $get
    $Line &= StdoutRead($get)
    If @error Then ExitLoop
Wend
$Line = StringSplit(StringStripCR($Line), @LF)
$Out = ""
For $I = 1 To $Line[0]
    If StringLeft($Line[$I], 2) = "\\" then
        $Line[$I] = StringTrimLeft($Line[$I], 2)
        $Out &= StringLeft($Line[$I], StringInStr($Line[$I], Chr(32))) & @CRLF
        MsgBox(0, "Computer", StringLeft($Line[$I], StringInStr($Line[$I], Chr(32))))
    EndIf
Next
MsgBox(0, "Finished", "Finished parsing computer list" & @CRLF & @CRLF & $Out)
Exit

$Out is probably not required for your purposes and replace the MsgBox in the If statement to what ever function you want to perform.

Edit: Spelling cops got me again!!!

That's some slick A$$ code but it took

>Exit code: 0 Time: 22.406 <--- To run throught my whole list of computers.. CODE worked PERFECT just slower then I would have hoped..

I was thinking more like 1 second.. or less

The way I read the code is its doing some fancy parsing but it also counting throught the PC's I think if it could take the $out and grab the names out of that .. Like it snapped a picture then broke all the pieces up and drop it in a database

Link to comment
Share on other sites

That's some slick A$$ code but it took

>Exit code: 0 Time: 22.406 <--- To run throught my whole list of computers.. CODE worked PERFECT just slower then I would have hoped..

I was thinking more like 1 second.. or less

The way I read the code is its doing some fancy parsing but it also counting throught the PC's I think if it could take the $out and grab the names out of that .. Like it snapped a picture then broke all the pieces up and drop it in a database

It's not counting through the PC's, it's parsing the StdOut stream. You could just let it build $Out and then run that through another loop after a StringSplit($Out, @CRLF) but that will slow it down again. Why not just replace the MsgBox(0, "Computer".........) with the database function you need to perform.

Also I have a hunch that if you wait for a while, someone will come along with another solution that uses RegExp(). All I'm really doing is showing that you have to wait for the StdOut stream before doing anything else otherwise your Run will exit before you have performed any operations.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

It's not counting through the PC's, it's parsing the StdOut stream. You could just let it build $Out and then run that through another loop after a StringSplit($Out, @CRLF) but that will slow it down again. Why not just replace the MsgBox(0, "Computer".........) with the database function you need to perform.

Also I have a hunch that if you wait for a while, someone will come along with another solution that uses RegExp(). All I'm really doing is showing that you have to wait for the StdOut stream before doing anything else otherwise your Run will exit before you have performed any operations.

I even tried it this way

#include <Constants.au3>

#include <String.au3>

$Line = ""

$get = Run(@ComSpec & " /c net view > " & "list.txt", @SystemDir, @SW_HIDE)

$file = FileOpen("list.txt",0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

While 1

$line = FileReadline($file)

IF StringLeft($LINE,2) = "\\" Then

$PC = StringMid($line,3,11)

If @error > 0 Then ExitLoop

Call("addlist",$PC) <---- Send to SQL DATABASE

Else

EndIf

Wend

FileClose($file)

Exit

--------------------------------------

Then AutoIT tcrashes when it reaches the end of the file and says ( X ) Error allocating memory.

| OK |

----------------------------------------

You get the point :D

Link to comment
Share on other sites

You would be better off to read the file to an array. Your method of reading the file is never going to work. For example FileReadLine($File) <<============ What line?? Where are you incrementing the line??

You could forget the whole file open thing and use

$File = _FileReadtoArray("List.txt")
For $I = 1 To Ubound($File)
  Do whatever
Next

Func _FileReadToArray($sFilePath)
Local $hFile
    $hFile = FileOpen($sFilePath, 0)
    If $hFile = -1 Then
        SetError(1)
        Return 0
    EndIf
    $aArray = StringSplit( StringStripCR( FileRead($hFile, FileGetSize($sFilePath))), @LF)
    FileClose($hFile)
    Return $aArray
EndFunc

But then you still have the time issue because you are looping through an array. I suspect it may even be slower than my original.

EDIT: I should have added that FileReadLine() is the slowest possible method of reading data from a file.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...