Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. net; using system. net. sockets; using system. text; using system. threading. tasks; using system. windows. forms; namespace scan computer port {public partial class form1: FORM {public form1 () {initializecomponent ();} private void button#click (Object sender, eventargs E) {Listbox1.items. clear (); If (string. isnullorempty (textbox1.text. trim () | string. isnullorempty (textbox2.text. trim () | string. isnullorempty (textbox3.text. trim () {MessageBox. show ("enter the port number and IP address... "," Prompt "); return;} IPaddress IP = IPaddress. parse (textbox3.text. trim (); // instantiate IPaddress class for (INT I = convert. toint32 (textbox1.text); I <convert. toint32 (textbox2.text) + 1; I ++) {tcpclient Tx = new tcpclient (); // instantiate try {Tx. connect (Ip, I); // use the IP address and port number to connect to the host. Listbox1.items. add ("com:" + I + "is open. ");} catch {} finally {Tx. close (); // release the instance, but do not close the basic connection .}} Listbox1.items. Add ("Scan ended! ");}}}
Scan the computer port number