Sign in to follow this  
Followers 0
Infinitex0

Port scanner

35 posts in this topic

#1 ·  Posted (edited)

well, I recently downloaded a port scanner and thought "this doesn't look to hard to make" so I opened up scite and made this. Its pretty simple......I'll probably redo it.

Heres the 2.0 version (much better)

#include <guiconstants.au3>

$PortScanner = GUICreate("Infinitex0's Port Scanner", 300, 175)
GUICtrlCreateGroup("Port Scan", 5, 5, 275, 160)
$IPLabel = GUICtrlCreateLabel("IP", 20, 17)
$PortIPAddress = GUICtrlCreateInput("127.0.0.1", 20, 33, 125)
GUICtrlCreateLabel("Start on Port", 20, 55)
$PortStartNumber = GUICtrlCreateInput("1", 20, 68, 125)
GUICtrlCreateLabel("End on Port", 20, 91)
$PortEndNumber = GUICtrlCreateInput("30", 20, 108, 125)
$StartScan = GUICtrlCreateButton("Start", 20, 135, 125)
GUICtrlSetFont($StartScan,15)
$OnPort = GUICtrlCreateLabel("Scanning Port:None", 150, 142)
GUICtrlCreateGroup("Open Ports", 160, 17,105, 125)
$OpenPortList=GUICtrlCreateList("", 168, 30, 90, 109)
GUICtrlCreateGroup ("",-99,-99,1,1)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_ClOSE
            ExitLoop
        Case $msg = $StartScan
            _StartScan()
    EndSelect
WEnd

Func _StartScan()
    $PortIP=GUICtrlRead($PortIPAddress)
    $PortEndNumberB=guictrlread($PortEndNumber)
    $PortStartNumberB=guictrlread($PortStartNumber)
    TCPStartup()
$timerstart = TimerInit()
For $LetsGo = $PortStartNumberB To $PortEndNumberB
$socket = TCPConnect($PortIP,$PortStartNumberB)
ControlSetText("", "", $OnPort, "Scanning Port:" & $PortStartNumberB & "")
If $socket = -1 Then
    $PortStartNumberB = $PortStartNumberB + 1
Else
    GUICtrlSetData($OpenPortList,$PortStartNumberB)
    $PortStartNumberB = $PortStartNumberB + 1
EndIf
Next
    TCPShutdown()
    $timerend = TimerDiff($timerstart)
    TrayTip("Port Scanner", "Done Process took " & Round($timerend,-1)/1000 & " seconds", 7, 1)
EndFunc

EDIT: wow, somehow the script got messed up fixed now.

NEW EDIT: wow, I totally fu....can I say that here..well I messed up and by a tiny math problem 2.0 scanned every other port, this is 2.5 which (besides a few small changes) fixes this so now all ports are scanned.

Edited by Infinitex0

The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites



I don't really know enough to say if that is really doing much of anything but I played with it and learned about timerstart and timerend. Thank you! Good work!


AutoIt changed my life.

Share this post


Link to post
Share on other sites

Port scanners are sometimes usefull (if you are SysAdmin), but are also the easyest way to get AutoIt blacklisted in some Antivirus or Network security program...

And also the easyest way to make your ISP or Network admin mad at you :)

Share this post


Link to post
Share on other sites

yea, I did know that these are used to check your own ports so you know if any are open to hackers (or crackers). One of the reasons I never put up the keylogger I made with autoit (besides the fact that its extremely easy), don't worry, I've never used it on anyone. I put in the timer thing so that I could see how fast it is. I think the max number of ports is like 65535. but even testing on your own comp it would take a while (almost a day) to do, with any scanner. Well, I think this is just what I needed to bring myself back to Autoit. I forgot how much I loved it.


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

Well, I think this is just what I needed to bring myself back to Autoit. I forgot how much I loved it.

True, true :) AutoIt is the best example of good balance between functionality and ease of use :P

Share this post


Link to post
Share on other sites

I dunno, I guess I could try making one


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

The UDP scanners DO exist, and I think doing one in AutoIt is not verry different from the TCP port scanner. Maybe just replace TCPConnect() with UDPOpen(), TCPStartup() and TCPShutdown() with UDPStartUp() and UDPShutdown()?

Share this post


Link to post
Share on other sites

I'm making one right now and I think its slightly different.


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

hmmm, well I made a UDP one but the problem is its counting all the ports as open......hmmmmmmmm


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

UDP is 'fire-and-forget'. That explains why the UDP functions do not return an error.

Fire up Wikipedia and view what is the difference between UDP and TCP.

Edit: Just found a nice bit on UDP port scanning.

UDP Scanning

Port scanning usually means scanning for TCP ports, which are connection-oriented and therefore give good feedback to the attacker. UDP responds in a different manner. In order to find UDP ports, the attacker generally sends empty UDP datagrams. If the port is listening, the service should send back an error message or ignore the incoming datagram. If the port is closed, then most operating systems send back an "ICMP Port Unreachable" message. Thus, you can find out if a port is NOT open, and by exclusion determine which ports are open. Neither UDP packets, nor the ICMP errors are guaranteed to arrive, so UDP scanners of this sort must also implement retransmission of packets that appear to be lost (or you will get a bunch of false positives).

Also, this scanning technique is slow because of compensation for machines that implement the suggestions of RFC 1812 and limit ICMP error message rate. For example, a kernal may limit destination unreachable message generation to 80 per 4 seconds, with a 1/4 second penalty if that is exceeded.

Some people think UDP scanning is pointless - not so. Sometimes for example, Rpcbind can be found hiding on an undocumented UDP port somewhere above 32770. So it doesn't matter that port 111 is blocked by the firewall. But can you find which of the more than 30,000 high ports it is listening on? With a UDP scanner you can.

Edited by Manadar

Share this post


Link to post
Share on other sites

I was considering the idea of exclusion instead of inclusion but as it says in the article it (and as I thought, but not to that extent) it takes a long time. O well, just settle for TCP........until I make UDP.....if I do.


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

UDP is what is called "unreliable." It is made for speed, so all the overhead of error checking, destination checking, etc, has been removed. As Manadar posted, you would need your own checking system.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Hi,

I rewrote your code:

$SocketIP = ""
$socketportstart = 1
$socketportend = 65535

TCPStartup()

For $port = $socketportstart To $socketportend
    $socket = TCPConnect($SocketIP,$port)
        
    If $socket = -1 Then
        ConsoleWrite($port & " - Unable to connect." & @CRLF)
    ElseIf $socket = 1 Then
        ConsoleWrite($port & " - Wrong Address" & @CRLF)
        ExitLoop
    ElseIf $socket = 2 Then
        ConsoleWrite($port & " - Wrong Port" & @CRLF)
    Else
        ConsoleWrite($port & " - Success!" & @CRLF)
    EndIf
Next

TCPShutdown()

As you can see, it can now easily run in Scite and give you all portnumbers and if they are open or not. And I replaced your loop with a i think better loop for this use.

Edited by Pakku

Share this post


Link to post
Share on other sites

only problem with that is people may not want to scan every port.


The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

Wow that was alot easier than I thought!

You should have a TCPCloseSocket() after the "Success" ...

Hallman

Share this post


Link to post
Share on other sites

Wow, that is pretty nice looking code Arjan. Simple, and easy to understand without running it.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Got to Playing with this, tried to make it a little faster, and found something out: TCPConnect returns -1 for Wrong Address and Port number as well, and it sets @error to 1 or 2, depending on the error. My Version (Still not that fast, mind you):

Opt("TCPTimeout",1)
$SocketIP = ""
$socketportstart = 1
$socketportend = 65535

TCPStartup()

For $port = $socketportstart To $socketportend
    $socket = TCPConnect($SocketIP,$port)   
    Switch $socket
        Case -1
            Switch @error  
                Case 1 
                    ConsoleWrite($port & " - Unable to connect - Wrong Address." & @CRLF)
                Case 2  
                    ConsoleWrite($port & " - Unable to connect - Wrong Port." & @CRLF)
                Case Else
                    ConsoleWrite($port & " - Unable to connect." & @CRLF)
            EndSwitch
        Case Else
            TCPCloseSocket($socket)
            ConsoleWrite($port & " - Success!" & @CRLF)
    EndSwitch
Next

TCPShutdown()
Edited by SkinnyWhiteGuy

Share this post


Link to post
Share on other sites

UDP is what is called "unreliable." It is made for speed, so all the overhead of error checking, destination checking, etc, has been removed. As Manadar posted, you would need your own checking system.

Unreliable Datagram Protocol. :)

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