Jump to content

Recommended Posts

Posted

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? 

  • Moderators
Posted

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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!

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

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

Posted

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

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

Posted

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.

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

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

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

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
×
×
  • Create New...