Sign in to follow this  
Followers 0
botanic

Multiple TCP connections at once?

3 posts in this topic

#1 ·  Posted (edited)

I am trying to use this script to find out what port ssh is running on for a number of servers for the place i just started working. The problem is that it works, just it is really slow as it only handles on request at a time. Is there any way to change that?

PS: yes i know its a port sniffer, my new job title is 1/2 server ninja 1/2 hacker ^_^

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\..\..\..\Users\Matthew Lagoe\Desktop\portscanner.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
MsgBox(0, "use", "to use this you need oswinsck")
Global Const $SCKTCPPROTOCOL = 0
Global Const $SCKUDPPROTOCOL = 0x01
Global Const $SCKCLOSED = 0
Global Const $SCKOPEN = 0x01
Global Const $SCKLISTENING = 0x02
Global Const $SCKCONNECTIONPENDING = 0x03
Global Const $SCKRESOLVINGHOST = 0x04
Global Const $SCKHOSTRESOLVED = 0x05
Global Const $SCKCONNECTING = 0x06
Global Const $SCKCONNECTED = 0x07
Global Const $SCKCLOSING = 0x08
Global Const $SCKERROR = 0x09




Dim $sIPADDRESS = InputBox("IP", "Type the ip") 
$file = FileOpen("C:\"&$sIPADDRESS&".txt", 10)
Dim $result = _ScanPorts($sIPADDRESS, 100, 1, 65535)

If Not IsArray($result) Then
    Switch $result
        Case -2
            MsgBox(0x10, "Host not reachable", "The host could not be reached")

        Case -3
            MsgBox(0x30, "Timeout not defined", "Please insert the desired amount of timeout(ms)")
    EndSwitch
Else
    _ArrayDisplay($result, 'Finish scanning IP address: ' & $sIPADDRESS)
    MsgBox(0, "Save", "File saved to C:\"&$sIPADDRESS&".txt")
EndIf

Exit



Func _ScanPorts($sIPADDRESS, $iTimeout, $iFrom, $iTo)
    Local $i, $step, $index = 0
    Local $ping, $result, $aResults[1]

    $ping = Ping($sIPADDRESS, $iTimeout)

    If Not $ping Then Return -2

    If $iTo < $iFrom Then
        $step = -1
        ReDim $aResults[$iFrom-$iTo+1]
    Else
        $step = 1
        ReDim $aResults[$iTo-$iFrom+1]
    EndIf


    For $i = $iFrom To $iTo Step $step
        $result = Connect($sIPADDRESS, $i, $iTimeout)
        If Not $result Then
            $aResults[$index] = 'Port: ' & $i & ' is open'
            $index += 1
    FileWrite($file, "Port " &$i& " open." & @CRLF)

        EndIf
    Next

    Return $aResults
EndFunc   ;==>_ScanPorts


Func Connect($sAddr, $iPort, $iTimeout)

    Local $oSocket, $timer
    $oSocket = ObjCreate("OSWINSCK.Winsock")

    $oSocket.Protocol = $SCKTCPPROTOCOL ; set protocol to be tcp
    $timer = TimerInit()
    $oSocket.Connect($sAddr, $iPort)

    While 1

        If $oSocket.State = $SCKERROR Then
            $oSocket = 0
            Return -2 ;connection error (will give up for now)
        EndIf

        If $oSocket.State = $SCKCONNECTED Then
            ;ConsoleWrite("timeout " & TimerDiff($timer) & @TAB & "On line: " & @ScriptLineNumber)
            $oSocket.CloseWinsock
            $oSocket = 0
            Return 0
            ;Return $oSocket ; return object for connection
        EndIf

        If TimerDiff($timer) > $iTimeout Then
            ;ConsoleWrite("timeout " & TimerDiff($timer) & @CRLF)
            $oSocket = 0
            Return -3 ; connection timeout
        EndIf

        Sleep(20)
    WEnd

EndFunc   ;==>Connect
Edited by botanic

Share this post


Link to post
Share on other sites



My friend used to use a program called netcat for windows to sniff ports within his own network. It worked reasonably fast and you can find it with google.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

You could use a threaded tool that can scan several systems simultaneously? I use this tool to scan my systems at home and work to ensure everything checks out from network/ports/services perspective. I am a network security administrator for gov systems and not a hacker of any sort. Please don't ban me for posting this, Nmap has been around for like 10 years, it's totally legit. NMAP Installer for Windows from Offical Site [www.nmap.org]


www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

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