moridin Posted May 25, 2007 Posted May 25, 2007 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
acidfear Posted May 25, 2007 Posted May 25, 2007 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()
Gif Posted May 25, 2007 Posted May 25, 2007 (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 May 25, 2007 by c4nm7
moridin Posted May 25, 2007 Author Posted May 25, 2007 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?
jokke Posted May 25, 2007 Posted May 25, 2007 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.
Gif Posted May 25, 2007 Posted May 25, 2007 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!
jokke Posted May 25, 2007 Posted May 25, 2007 (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 May 25, 2007 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.
moridin Posted May 25, 2007 Author Posted May 25, 2007 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?
jokke Posted May 25, 2007 Posted May 25, 2007 (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. expandcollapse popup;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 May 25, 2007 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.
jokke Posted May 25, 2007 Posted May 25, 2007 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.
moridin Posted May 25, 2007 Author Posted May 25, 2007 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?
jokke Posted May 25, 2007 Posted May 25, 2007 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.
moridin Posted May 26, 2007 Author Posted May 26, 2007 (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 May 26, 2007 by moridin
mike007 Posted June 6, 2007 Posted June 6, 2007 Could this be used as a type of stand by mod for xbox live on Halo 2?
andyvl Posted August 26, 2007 Posted August 26, 2007 (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 August 26, 2007 by andyvl
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now