📄 tcpclient1.aspx
字号:
<% @ Page Language="C#" Trace="True" TraceMode="SortByCategory" %>
<% @ Import Namespace="System.Net.Sockets" %>
<% @ Import Namespace="System.IO" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
int[] arrPort = new int[4]{21,23,25,110};
string strServer = "localhost";
string strService,strResponse,strShow;
int intPort;
for(int i=0;i<arrPort.Length;i++)
{
intPort = arrPort[i];
Trace.Warn("程序正在判断打开端口所提供的服务");
switch(intPort)
{
case 21:
strService = "FTP服务";
break;
case 23:
strService = "Telnet服务";
break;
case 25:
strService = "SMTP服务";
break;
case 110:
strService = "POP3服务";
break;
default:
strService = "无法知道";
break;
}
if((strResponse=TcpConnect(strServer,intPort))!="没有开放")
{
Trace.Warn(intPort.ToString()+"端口开放");
strShow = "<b>"+intPort.ToString()+"</b>端口:"+strResponse+"(<font color=red>"+strService+"</font>)";
}
else
{
Trace.Warn(intPort.ToString()+"端口未开放");
strShow = "<b>"+intPort.ToString()+"</b>端口没有开放"+"(<font color=red>"+strService+"</font>)";
}
pnlServer.Controls.Add(new LiteralControl(strShow+"<p>"));
}
}
public string TcpConnect(string strServer,int intPort)
{
string strResult;
TcpClient tcpc = new TcpClient();
try
{
tcpc.Connect(strServer,intPort);
Stream s = tcpc.GetStream();
StreamReader sr = new StreamReader(s,Encoding.Default);
strResult = sr.ReadLine();
}
catch(Exception ee)
{
strResult = "没有开放";
}
finally
{
tcpc.Close();
}
return strResult;
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<b>使用TcpClient探测主机信息</b>
<form runat="server">
<asp:Panel id="pnlServer" runat="server" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -