I installed a device on my computer (for example a cardreader). I ran this code but the ComboBox was not filled.
Code:
using System.Management;
using System.IO.Ports;
foreach (string portname in SerialPort.GetPortNames())
{
comboBox1.Items.Add(portname);
}
Since this didn’t work, how can I see the port addresses and properties of the devices installed on the computer?
The GetPortNames() function provides a list of the serial port names see GetPortNames() page which are not sockets.
Here is documentation on the SerialPort class which has methods that you can use to determine the properties of a particular serial port including baud rate, etc. I suspect that the basic outline of what you want is to use the
SerialPort.GetPortNames()method to generate a list of port names and to then use theSerialPort (String)to interogate the properties of the specific port as you iterate through the list of ports provided byGetPortNames().If it is actually sockets you are interested in, you may want to know a list of well know TCP and UDP ports however like the pirate’s code these are more like guidelines than actual rules and what is actually on a port may not be what the standard usage documents. It depends on what software is running and how the software is configured. I do not know of any way of knowing what service may be using a particular port other than going by the standard list, sending a service specific query to the port, or to use a utility such as netstat to generate a list.