我只想检查smpp服务器是否接受连接。我们可以使用命令提示符使用以下命令检查它:telnet 152.26.53.39 2775
我只想在C#中编写此命令
答案 0 :(得分:1)
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect("152.26.53.39", 2775);
Console.WriteLine("Port 2775 Open");
}
catch (Exception){
Console.WriteLine("Port 2775 Closed");
}
答案 1 :(得分:0)
您可以使用Ping class,如下所示:
string nameOrAddress="152.26.53.39 2775";
public static bool PingHost(string nameOrAddress)
{
bool pingable = false;
Ping pinger = new Ping();
try
{
PingReply reply = pinger.Send(nameOrAddress);
pingable = reply.Status == IPStatus.Success;
}
catch (PingException)
{
// Discard PingExceptions and return false;
}
return pingable;
}