Skip to content
Fix Code Error

How to close TCP and UDP ports via windows command line

March 13, 2021 by Code Error
Posted By: Anonymous

Does somebody knows how to close a TCP or UDP socket for a single connection via windows command line?

Googling about this, I saw some people asking the same thing. But the answers looked like a manual page of netstat or netsh commands focusing on how to monitor the ports. I don’t want answers on how to monitor them (I already do this). I want to close/kill them.

EDIT, for clarification: Let’s say that my server listens TCP port 80. A client makes a connection and port 56789 is allocated for it. Then, I discover that this connection is undesired (e.g. this user is doing bad things, we asked them to stop but the connection didn’t get dropped somewhere along the way). Normally, I would add a firewall to do the job, but this would take some time, and I was in an emergency situation. Killing the process that owns the connection is really a bad idea here because this would take down the server (all users would lose functionality when we just want to selectively and temporally drop this one connection).

Solution

Yes, this is possible. You don’t have to be the current process owning the socket to close it. Consider for a moment that the remote machine, the network card, the network cable, and your OS can all cause the socket to close.

Consider also that Fiddler and Desktop VPN software can insert themselves into the network stack and show you all your traffic or reroute all your traffic.

So all you really need is either for Windows to provide an API that allows this directly, or for someone to have written a program that operates somewhat like a VPN or Fiddler and gives you a way to close sockets that pass through it.

There is at least one program (CurrPorts) that does exactly this and I used it today for the purpose of closing specific sockets on a process that was started before CurrPorts was started. To do this you must run it as administrator, of course.

Note that it is probably not easily possible to cause a program to not listen on a port (well, it is possible but that capability is referred to as a firewall…), but I don’t think that was being asked here. I believe the question is “how do I selectively close one active connection (socket) to the port my program is listening on?”. The wording of the question is a bit off because a port number for the undesired inbound client connection is given and it was referred to as “port” but it’s pretty clear that it was a reference to that one socket and not the listening port.

Answered By: Anonymous

Related Articles

  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • XAMPP Port 80 in use by "Unable to open process" with PID 4
  • Use SQL Server Management Studio to connect remotely…
  • java.io.EOFException when reading from socket
  • How to fix browser-sync & socket.io conflict?
  • Sending data to TCPServer more than one time
  • How to create websockets server in PHP
  • What is the difference between net.createServer()…
  • NEXTJS, React, socketio, Rasberry Pi, DS18B20 - How…
  • error LNK2005: ✘✘✘ already defined in…
  • WebSocket connection failed: Error during WebSocket…
  • A request to send or receive data was disallowed…
  • Rust: implementing an iterator from a vector of…
  • What does Python's socket.recv() return for…
  • Connecting client to server using Socket.io
  • Start redis-server with config file
  • problem with client server unix domain stream…
  • Reference — What does this symbol mean in PHP?
  • Cannot connect to SQL Server named instance from…
  • How To Implement React hook Socketio in Next.js
  • Apache server keeps crashing, "caught SIGTERM,…
  • Error: Address already in use while binding socket…
  • stop all instances of node.js server
  • Simple C example of doing an HTTP POST and consuming…
  • Creating an dynamic array, but getting segmentation…
  • Memcached vs. Redis?
  • Why am I getting the error "connection refused" in…
  • Windows could not start the Apache2 on Local…
  • Aurelia using featherjs dependency failing to…
  • How to import socket.io.client javascript in polymer…
  • render function or template not defined in…
  • How to correctly create a custom socket method with…
  • TCP vs UDP on video stream
  • Socket.io and Backbone
  • Python send UDP packet
  • Sending string via socket (python)
  • Nodejs Socket.io getting user from on("connection") event
  • Socket.io double events, solved for connect BUT not…
  • What is an example of the simplest possible…
  • Python: Binding Socket: "Address already in use"
  • What is your most productive shortcut with Vim?
  • How to kill all processes matching a name?
  • socket programming multiple client to one server
  • error: 'Can't connect to local MySQL server through…
  • What are the undocumented features and limitations…
  • Use socket server connection at different code files…
  • How do I connect to this localhost from another…
  • How to reconnect a websocket connection after manual…
  • When is it appropriate to use UDP instead of TCP?
  • Python socket.error: [Errno 111] Connection refused
  • TCP client/server in c
  • Best TCP port number range for internal applications
  • Understanding INADDR_ANY for socket programming
  • How to make my vue component connect to my node server
  • Enabling/Disabling Microsoft Virtual WiFi Miniport
  • How to change XAMPP apache server port?
  • Receive WebSockets data from vuex and…
  • Read data both ways TCPServer Ruby
  • How to use dynamic socket url in components?
  • How can I send emails through SSL SMTP with the .NET…
  • Simple UDP example to send and receive data from same socket
  • java.io.StreamCorruptedException: invalid stream…
  • MQTT paho - no error when failed to publish message
  • Cant connect to socket io server on cpanel https
  • How to fix 400 error bad request in socket io?
  • How to handle a redis connection error in express?
  • use "netsh wlan set hostednetwork ..." to create a…
  • Rust Datagram Socket: How to receive string from bytes
  • connection event gets triggered infinite times for…
  • How to check internet access on Android? InetAddress…
  • Javax.net.ssl.SSLHandshakeException:…
  • Using Vue.js with vue-socket-io
  • socket.on not working in client side
  • Get operating system info
  • socket.error:[errno 99] cannot assign requested…
  • how to make a self made TLS packet appear as tls in…
  • IOException: read failed, socket might closed -…
  • postgresql port confusion 5433 or 5432?
  • VueJS with vue-socket-io not displaying anything
  • Differences between TCP sockets and web sockets, one…
  • Socket.IO handling disconnect event
  • How do multiple clients connect simultaneously to…
  • nginx - nginx: [emerg] bind() to [::]:80 failed (98:…
  • java.net.ConnectException: Connection refused
  • jQuery Mobile: document ready vs. page events
  • mysqli::mysqli(): (HY000/2002): Can't connect to…
  • java.rmi.ConnectException: Connection refused to…
  • Find (and kill) process locking port 3000 on Mac
  • Timeout a command in bash without unnecessary delay
  • Getting the IP address of the current machine using Java
  • In what situations would AJAX long/short polling be…
  • Polymer dom-repeat not rendering changes with…
  • Is there a way to process CRL updates without…
  • What happens when a UDP socket calls a TCP socket
  • Server Client send/receive simple text
  • SSH -L connection successful, but localhost port…
  • Can not connect to local PostgreSQL
  • Overriding .fetch() works with fake data, errors…
  • Handling a timeout error in python sockets
  • How to get gulp-vulcanize to ignore socket.io.js?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

What is the –save option for npm install?

Next Post:

How to loop through all enum values in C#?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error