Jump to content

Port Block


Recommended Posts

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

Link to comment
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()

Link to comment
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()

TcpStartup()
$onin = TcpListen($IP, $blockingPort)
TcpAccept($onin)
sleep(100)
TcpCloseSocket($onin)
TcpShutdown()
Edited by c4nm7
Link to comment
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?

Link to comment
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.
Link to comment
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!

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...