Jump to content
Sign in to follow this  
TheOnlyOne

Port scanning

Recommended Posts

TheOnlyOne

okay i am trying to create a port scanner

first i looked in the help file for tcpconnect()

then i saw that if the @error was 2 then the port is not valid

but the problem is that its searching for like 2 min for 1 port?

this is my script for now

tcpstartup()
$file=@ScriptDir&"\ip.txt"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
AutoItSetOption("TCPTimeout",25)
local $ip,$port,$speed=100
$r=fileread($file)
#Region ### START Koda GUI section ### Form=C:\Users\Rasmus\Desktop\jobs\portscan\design.kxf
$Form1_1 = GUICreate("Form1", 302, 325, 197, 119)
$ListView1 = GUICtrlCreateListView("", 16, 88, 250, 150)
$Input1 = GUICtrlCreateInput("0", 16, 56, 49, 21)
$Input2 = GUICtrlCreateInput("65535", 92, 56, 41, 21)
$Label1 = GUICtrlCreateLabel("Port Range", 48, 32, 58, 17)
$Label2 = GUICtrlCreateLabel("__", 72, 52, 16, 17)
$Label3 = GUICtrlCreateLabel("Current ip scanning:"&$ip, 24, 256, 150, 17)
$Label4 = GUICtrlCreateLabel("Current port scanning:"&$port, 24, 280, 130, 17)
$msg = GUICtrlCreateButton("Start Scan", 8, 8, 75, 17, $WS_GROUP)
$Radio1 = GUICtrlCreateRadio("Speed 1(Slow)", 176, 8, 113, 17)
$Radio2 = GUICtrlCreateRadio("Speed 2 (Medium", 176, 32, 113, 17)
$Radio3 = GUICtrlCreateRadio("Speed 3(Fast)", 176, 56, 113, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$1=1
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Radio1
            $speed=100
        case $Radio2
            $speed=75
        case $Radio3
            $speed=50
        case $msg
            if $r<>"" then
            $1port=guictrlread($input1)
            $2port=guictrlread($input2)
            _scan()
        Else
            msgbox(0,"Error","File is empty")
        EndIf

    EndSwitch
WEnd




func _scan()
    $1=0
    for $d= 1 to _FileCountLines($file)
        for $port=$1port to $2port
        $ip=filereadline($file,$d)
        guictrlsetdata($label3,"Current ip scanning:"&$ip)
        guictrlsetdata($label4,"Current port scanning:"&$port)
        sleep($speed)
        $connect=TCPconnect($ip,$port)
if not @error Then
    _found()
EndIf
Next
Next

EndFunc

func _found()
GUICtrlCreateListViewItem("ip:"&$ip&"                 port:"&$port,$1)
$1=$1+1

EndFunc

so how can i make it faster?

Share this post


Link to post
Share on other sites
martin

okay i am trying to create a port scanner

first i looked in the help file for tcpconnect()

then i saw that if the @error was 2 then the port is not valid

but the problem is that its searching for like 2 min for 1 port?

this is my script for now

tcpstartup()
$file=@ScriptDir&"\ip.txt"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
AutoItSetOption("TCPTimeout",25)
local $ip,$port,$speed=100
$r=fileread($file)
#Region ### START Koda GUI section ### Form=C:\Users\Rasmus\Desktop\jobs\portscan\design.kxf
$Form1_1 = GUICreate("Form1", 302, 325, 197, 119)
$ListView1 = GUICtrlCreateListView("", 16, 88, 250, 150)
$Input1 = GUICtrlCreateInput("0", 16, 56, 49, 21)
$Input2 = GUICtrlCreateInput("65535", 92, 56, 41, 21)
$Label1 = GUICtrlCreateLabel("Port Range", 48, 32, 58, 17)
$Label2 = GUICtrlCreateLabel("__", 72, 52, 16, 17)
$Label3 = GUICtrlCreateLabel("Current ip scanning:"&$ip, 24, 256, 150, 17)
$Label4 = GUICtrlCreateLabel("Current port scanning:"&$port, 24, 280, 130, 17)
$msg = GUICtrlCreateButton("Start Scan", 8, 8, 75, 17, $WS_GROUP)
$Radio1 = GUICtrlCreateRadio("Speed 1(Slow)", 176, 8, 113, 17)
$Radio2 = GUICtrlCreateRadio("Speed 2 (Medium", 176, 32, 113, 17)
$Radio3 = GUICtrlCreateRadio("Speed 3(Fast)", 176, 56, 113, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$1=1
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Radio1
            $speed=100
        case $Radio2
            $speed=75
        case $Radio3
            $speed=50
        case $msg
            if $r<>"" then
            $1port=guictrlread($input1)
            $2port=guictrlread($input2)
            _scan()
        Else
            msgbox(0,"Error","File is empty")
        EndIf

    EndSwitch
WEnd




func _scan()
    $1=0
    for $d= 1 to _FileCountLines($file)
        for $port=$1port to $2port
        $ip=filereadline($file,$d)
        guictrlsetdata($label3,"Current ip scanning:"&$ip)
        guictrlsetdata($label4,"Current port scanning:"&$port)
        sleep($speed)
        $connect=TCPconnect($ip,$port)
if not @error Then
    _found()
EndIf
Next
Next

EndFunc

func _found()
GUICtrlCreateListViewItem("ip:"&$ip&" port:"&$port,$1)
$1=$1+1

EndFunc

so how can i make it faster?

What are you entering for port1 and port2 in the inpputs?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
TheOnlyOne

Martin

inside the function _scan()

func _scan()
    $1=0
    for $d= 1 to _FileCountLines($file)
        for $port=$1port to $2port
        $ip=filereadline($file,$d)
        guictrlsetdata($label3,"Current ip scanning:"&$ip)
        guictrlsetdata($label4,"Current port scanning:"&$port)
        sleep($speed)
        $connect=TCPconnect($ip,$port)
if not @error Then
    _found()
EndIf
Next
Next

EndFunc

in the for loop

and this is used to set witch ports you want to scan

Edited by TheOnlyOne

Share this post


Link to post
Share on other sites
TheOnlyOne

still need help?

wounder of there would be a whole other way to do this?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.