Sign in to follow this  
Followers 0
TomSawyer

Help on building a script

8 posts in this topic

I've got here a script with makes a tcp connection test on a txt file, on that script i would like to add two outputs on two separate txt files! One with the good ip.s and another with the bad ip.s! Will you help? 

Share this post


Link to post
Share on other sites



@TomSawyer I have moved your post to the appropriate forum. How about you post what you have tried thus far?  If you are at a total loss as to where to begin, you can look at the TCP* functions in the help file.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

This is what i get so far... i'm not a expert... but want to manage a small network... 

$blah = FileReadToArray("IPlist.txt")

TCPStartup()

for $ip in $blah
   $ip = StringSplit($ip,":")
   ConsoleWrite("IP: " & $ip[1] & " on port: "& $ip[2])
   $test = TCPConnect($ip[1],$ip[2])
   ConsoleWrite(" - " & $test & @CrLf)
next

 

It performs a test, and gives a --1 if the ip isn't working, and a -200 or so if the ip is working! I want that on two separate txt files... and i'm not getting it... sorry but i'm really a noob!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Maybe:
 

TCPStartup() ; Start the TCP service.

OnAutoItExitRegister("OnAutoItExit")

Local $sListIP = FileReadToArray("IPlist.txt")
Local $sIPAddress, $iPort, $iSocket, $iError, $IPPort
Local $NewListIPGood, $NewListIPBab

For $i = 0 To UBound($sListIP) - 1
    $IPPort = StringSplit($sListIP[$i], ":")
    If IsArray($IPPort) Then
        If $IPPort[0] > 1 Then
            $sIPAddress = $IPPort[1]
            $iPort = $IPPort[2]
            $iSocket = TCPConnect($sIPAddress, $iPort)
            $iError = @error
            If $iError Then
                $NewListIPBab &= $sListIP[$i] & @CRLF
                ConsoleWrite($sListIP[$i] & " -> Could not connect, Error code: " & $iError & @CRLF)
            Else
                $NewListIPGood &= $sListIP[$i] & @CRLF
                ConsoleWrite($sListIP[$i] & " -> Connection successful, Socket Identifier: " & $iSocket & @CRLF)
            EndIf
            TCPCloseSocket($iSocket); Close the socket.
        EndIf
    EndIf
Next

FileWrite("IPlistGood.txt", $NewListIPGood)
FileWrite("IPlistBad.txt", $NewListIPBab)

Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

 

Edited by VIP
@CRLF

Regards,
 

Share this post


Link to post
Share on other sites

Amazing... Would like to know as much as you guys...  thank you...

Share this post


Link to post
Share on other sites

@VIP despite the start with your ridiculous avatar, you seem to write very nice scripts.  If you would do so and offer links or further explanations to the OP, rather than just dispensing of legit answers, you would embarrass the rest of us old timers who just mock and and play a secret game of "whoever does it in the fewest lines wins".


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

You're right, but I just stood on the position of the people who need help and want their problems to be resolved as quickly as possible.

I do not know if when I say try using FileWrite, TCPConnect, ... for starters, they do not know when it will finish a script can run.
Although feeling to do it yourself something nice, but it takes a lot of time.


Regards,
 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This is just pseudo code because I cant get TCPconnect ( at all, not only in this configuration, but at all, ever) to do anything but return -1, but:

$hSux = FileOpen("Success.Log" , 9)
$hFail = FileOpen("Failure.log" , 9)
TCPStartup()
$AndThenSomeTernaryFTW = TCPConnect("127.0.0.1" , 65432) > 0 ? FileWrite($hSux , "Success! " & @HOUR & ":" & @MIN & "." & @SEC & @CRLF & "---") : FileWrite($hFail , "Fail! " & @HOUR & ":" & @MIN & "." & @SEC & @CRLF & "---")
TCPShutdown()
FileClose($hSux)
FileClose($hFail)

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
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
Sign in to follow this  
Followers 0