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).
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.
1900 above is the port number in my case. I use this most times when I want to close a port that React-Native developer tools (and Expo) is running on. Reason being that even after closing the developer window or stopping the server, the port still somehow remains in use.
However, there is another option which is telling the client to close its socket. Sending a RST TCP packet to the port the client is connecting on will cause the client to drop their connection. You can do that with RST scanning using nmap.
wkillcx is a reliable windows command line tool for killing tcp connections from the command line that hasn't been mentioned. It does have issues with servers with large number of connections sometimes though. I sometimes use tcpview for interactive kills but wkillcx can be used in scripts.
instant/feasible/partial answer :
unlike from the previous answer where netstat -a -o -n was used incredibly long list was to be looked into without the name of application using those ports
If you're runnning on Windows 8,`Windows Server 2012 or above with PowerShell v4 of above installed, you can use the below script. This finds the processes associated with the port & terminates them (i.e. kills the process along with its connection; not just the connection).
When you connect to a computer (either a Windows client or Windows Server) through the Remote Desktop client, the Remote Desktop feature on your computer "hears" the connection request through a defined listening port (3389 by default). You can change that listening port on Windows computers by modifying the registry.
The next time you connect to this computer by using the Remote Desktop connection, you must type the new port. If you're using a firewall, make sure to configure your firewall to permit connections to the new port number.
Then you can see the PID run on your port. Then copy that PID number. ( PID is a unique number that helps identify a hardware product or a registered software product.) And type below code line and press enter.
If you're using Windows Terminal then the killing process might be little less tedious.I've been using windows terminal and kill PID works fine for me to kill processes on the port as the new Windows Terminal supports certain bash commands. For example: kill 13300
Read this whole post, there's a lot initially but there's really just two or three small pieces. It'll be worth it because you'll be able to have a nice one click menu and drop directly into a serial port terminal on Windows in the Windows Terminal
Often when you're doing embedded systems development you'll want to monitor or talk to the COM/Serial Port just like you SSH into remote system. Folks ask questions like "How to connect to a serial port as simple as using SSH?"
Let's assume this device talks to the COM port as if it were a terminal and it's outputting stuff I want to see. I'll use this great little CLI example app for Arduino from Mads Aasvik to simulate such a device.
Screen is somewhat persnickety for Serial Port work so try Minicom. Minicom is a nice little text com program. Install with apt install minicom and run for the first time with "sudo minicom -s" to set your default. Note I've change the default port from /dev/modem to /dev/ttyS4 and the speed, in my case, to 9600.
This could be the Windows drivers not installed properly, please update the Seeed ArduinoSAMD board library to the latest version (1.7.8), we have added the windows driver, so when you update the board library to the latest, it also installed the driver.
I had been running version 1.7.8 SAMD Boards. Apparently when I updated the "Arduino SAMD Boards (32-bits ARM Cortex-MO+) to version 1.8.7 it modified the USB drivers and allowed my wayward WIO Terminal to work for a short time. Now I am still having the same USB driver issue loosing connection during an upload with only one of my WIO Terminals! It also got really hot. Does the WIO Battery expansion with extra ports, add-on, cause that?
Should I down grade SAMD Board to 1.7.7 and re-install to 1.7.8? Any other ideas?
to download my trained model onto WIO Terminal board. However compiling and uploading the sketch the WIO Terminal board gets disconnected from the system and Arduino IDE says "Board not found COMX port).
Thanks a lot. I like the simplicity of this. However after trying it to command a device I had trouble using the serial port with another program, e.g. Reaterm. Had to power cycle to clear. How do I inspect or clear the serial port status to make sure it is in pristine power on condition. (I may try your ComPrinter as the other program to see if it also hangs.) Inspecting and clearing a serial port without having to cycle power would be good to be able to do.
So with the aid of your tools I could solve my problem finally. Thank you very much. Another positive aspect of using cour programs is that they also work with lower com port numbers, so there is a chance to use the whole thing in combination with hardware com ports, too.
Hello sir, I am happy to see this post but I am searching a simple c program that can transmit a single character on serial port In windows 7 64 bit os to my microcontroller based designed. Will you please help me regarding this issue.??
Dear Sir
I need a command prompt or (a batch file) that can continuously send the ASCII code of a keyboard key when pressed to a specific serial port.
Also if it can prompt the user to enter the serial port number before starting that would be great.
It makes sense to use hyper-terminal for just sending some string (only ASCII visible characters and not binary data) with no additional software. But for anything more than that.. docklight or similar program would be nice to have
While hard to believe, I am running Windows XP. I have two XP laptops that communicate with each other via modems attached to each of their serial ports. The COM ports for the modems and the laptops are configured identically and correctly.
I used to see com ports via the device manager in windows 10. I've installed the Link 009 drivers for stm32 boards and I get the original virtual port I'm used to in Windows 8 however it has an error code 10 that the device cannot be used. I've looked through 5 tutorials and nothing is helping. Windows 10 seems to eliminate the COM ports and there's no way to recognize the board through these so I can use a terminal debug window. I really need to printf debug items and I need to get the Com ports working again.
ss -tnlp and netstat -tnlp shows pid of processes, their names and their open/listening (aka server) ports. There are tons of tutorials @google about these two commands. top on the other hand does not show open ports. Depending on the OS it can have some shortcuts to kill.
Sooner or later you're going to need kill some process to free some port. It's a good idea to glance some docs/manuals (man ss, man netstat) to have some vague memories about what each of these commands can do. Every command is useful. Everyone has their favourite set. Do an experiment - but before you do save your files.
Yeah. I had a port 80 problem when Dropbox was running in the background. As soon as I changed that (i.e. now Dropbox only runs when I open it instead of when I switch the laptop on), my problem was fixed. You can see what occupies your port 80 by running sudo lsof -i :YourPortNumber.
changing your root permissions? unix.stackexchange.com/questions/1...
Luckily, if you stop the application, the port will be released. The title says How to properly close a port?, not how to kill a process. What if you want the keep the process running but don't want to listen on that port anymore?
Hercules SETUP utility is useful serial port terminal (RS-485 or RS-232 terminal), UDP/IP terminal and TCP/IP Client Server terminal. It was created for HW group internal use only, but today it's includes many functions in one utility and it's Freeware! With our original devices (Serial/Ethernet Converter, RS-232/Ethernet Buffer or I/O Controller) it can be used for the UDP Config.
TCP server lisening on specified port in the Server status and show received data in RAW format. You can try Listen on port 80 on your PC and entry your IP address into your browser..
Note: Don't use receiveing port lower than 1024 in MS Windows, it can make you troubles with TCP/IP comunication, because Windows using these port numbers for system functions.