你怎么知道https(8443)端口是开放的&你怎么知道ftp端口是开放的 [英] How do you know https(8443) port is open & How do you know ftp port is open
本文介绍了你怎么知道https(8443)端口是开放的&你怎么知道ftp端口是开放的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你怎么知道https(8443)端口是打开的
你怎么知道ftp端口是打开的
解决方案
您不必编写代码来检查端口是否打开。你可以使用telnet应用程序:
telnet localhost 21
但是如果你需要在代码中检查它,你可以使用TcpClient:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Net.Sockets;
使用 System.Text;
使用 System.Threading.Tasks;
命名空间 Test_TcpConnect
{
class Program
{
静态 void Main(字符串 [] args)
{
尝试
{
使用(TcpClient cl = new TcpClient( localhost, 21 ))
{
Console.WriteLine( connected);
}
}
catch (例外情况)
{
Console.WriteLine(ex);
}
}
}
}
试试这个。
< pre lang =c#> bool IsOpen( int port)
{
IPGlobalProperties Properties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint [] EndPoints = Properties.GetActiveTcpListeners();
foreach (IPEndPoint i in EndPoints)
{
if (i.Port == port)
return 真跨度>;
}
返回 false ;
}
How do you know https(8443) port is open
How do you know ftp port is open
解决方案
you don't have to write code to check whether a port is open or not. you can use telnet application:
telnet localhost 21
But if you need to check it in code, you can use TcpClient:
using System; using System.Collections.Generic; using System.Linq; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; namespace Test_TcpConnect { class Program { static void Main(string[] args) { try { using (TcpClient cl = new TcpClient("localhost", 21)) { Console.WriteLine("connected"); } } catch (Exception ex) { Console.WriteLine(ex); } } } }
try this.
bool IsOpen(int port) { IPGlobalProperties Properties = IPGlobalProperties.GetIPGlobalProperties(); IPEndPoint[] EndPoints = Properties.GetActiveTcpListeners(); foreach (IPEndPoint i in EndPoints) { if (i.Port == port) return true; } return false; }
这篇关于你怎么知道https(8443)端口是开放的&你怎么知道ftp端口是开放的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文