Sign in to follow this  
Followers 0
moridin

Port Block

15 posts in this topic

I'm trying to write a script that can block certain local tcp ports on a computer. I also would like to be able to kill a connection on a port. I have searched the forum extensively and I cannot find anything relevant (doesn't mean the answer isn't there, just that i can't find it.) I would to point out that I'm not trying to create a firewall, and a firewall will not help me, so don't suggest getting a firewall. I also blocking ports trough my router isn't an option, so don't suggest that either please.

Is it possible? if so, how?

-Moridin

Share this post


Link to post
Share on other sites



I'm not sure you can block it, but what if you accept the connection on the port, and immediatly after have it close. So every time it attempts to connect, it gets dropped ?

TcpStart()

TcpListen() Listen for the port you want

TcpAccept() Accept it

TcpCloseSocket() Then close it immediatly after

TcpShutdown()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm not sure you can block it, but what if you accept the connection on the port, and immediatly after have it close. So every time it attempts to connect, it gets dropped ?

TcpStart()

TcpListen() Listen for the port you want

TcpAccept() Accept it

TcpCloseSocket() Then close it immediatly after

TcpShutdown()

TcpStartup()
$onin = TcpListen($IP, $blockingPort)
TcpAccept($onin)
sleep(100)
TcpCloseSocket($onin)
TcpShutdown()
Edited by c4nm7

Share this post


Link to post
Share on other sites

thanks for the replies, but that does not work, because as soon as autoit closes the port it is free for other programs to use.

Would a continuous loop that connects then disconnects work maybe?

Share this post


Link to post
Share on other sites

you could set the port as in use, then none would be able to connect.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

thanks for the replies, but that does not work, because as soon as autoit closes the port it is free for other programs to use.

Would a continuous loop that connects then disconnects work maybe?

eh keep the program open!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Damn i just loved the idea, AutoIT firewall :)

Single port firewall:

;firewall

TcpStartup()

$blockingPort = 23

While 1
    $ConnectedSocket = -1
    $MainSocket = -1
    $MainSocket = TcpListen(@IPAddress1, $blockingPort)
    If $MainSocket = -1 Then Exit
        
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    

    
    TCPSend($ConnectedSocket,'Port '&$blockingPort&' is blocked.')

    While 1
        $RogueSocket = TCPAccept( $MainSocket)
        If $RogueSocket > 0 Then 
            TCPSend( $RogueSocket, 'Port '&$blockingPort&' is blocked.' )
        EndIf
        $recv = TCPRecv($ConnectedSocket,1000)
        If @error Then
            ;connection closed.
            TCPCloseSocket($ConnectedSocket)
            $ConnectedSocket = -1
            $MainSocket = -1
        EndIf
    WEnd
WEnd
Edited by jokke

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

You're a bloody legend, it works!

Do you know if it is possible to kill a currently active connection, instead of and error being spat out?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

and here is a multi port blocker, it will tell inn console if error opening a port, means its allready used ( i think :) )

if you close 2000 ports, script takes about 20 - 30 sec to tell user that port is closed.

;firewall

TcpStartup()

$from = 1
$to = 500

Dim $portsocket[$to+1]

While 1
    For $x = $from To $to
        $portsocket[$x] = TcpListen(@IPAddress1, $x)
        If $portsocket[$x] = -1 Then 
            ConsoleWrite('error opening port: '&$x&@CRLF)
;~          Exit
        EndIf
    Next
    

    Do
        For $x = $from To $to
            $ConnectedSocket = TCPAccept($portsocket[$x])
            If $ConnectedSocket <> -1 Then
                TCPSend($ConnectedSocket,'Port '&$x&' is blocked.')
                TCPCloseSocket($ConnectedSocket)
            EndIf
        Next
    Until $ConnectedSocket <> -1


    While 1
        $recv = TCPRecv($ConnectedSocket,1000)
        If @error Then
            ;connection closed.
            TCPCloseSocket($ConnectedSocket)
            $ConnectedSocket = -1
            $MainSocket = -1
        EndIf
    WEnd
WEnd
Edited by jokke

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

the multi port firewall will close connection right after user have been alerted if port is blocked.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

Awesome. I spent a bit of today writing some nearly identical code, but I couldn't get it to work.

Any ideas on how to block a connection that is currently connected? Anybody?

Share this post


Link to post
Share on other sites

you wont be able to close an connection made before script was started, unless you kill the process using the connection.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ok then. But I did find a vb program, Emsa Port Blocker, that can. And it doesn't kill the process that is using that port. It also doesn't block the port by connecting to it like the firewall you (jokke) posted, it just stops it. It is free, but they haven't released the source code, so I can't look at it.

Are these things impossible to do in autoit?

Edited by moridin

Share this post


Link to post
Share on other sites

Could this be used as a type of stand by mod for xbox live on Halo 2?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Hmm, I guessed it worked but it isn't (or it doesn't have the functionality I think it has)

When I change port to 8080, I still am able to surf on the internet.

How can I adjust the script that the user (on pc where script is running) can't use certain ports (telnet, ftp, http) on his computer

Edited by andyvl

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