gpt4 book ai didi

javascript - 如何在 MVC 的 C# 中使用本地 IP 地址扫描客户机的开放端口?

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:03 25 4
gpt4 key购买 nike

我正在使用 MVC 开发 Web 应用程序。当用户登录网站时,我得到用户的本地 IP 地址。但是现在我想做的是扫描客户端本地机器的开放端口列表。

有什么方法可以在 MVC 中用 JavaScript 或 jQuery 或 C# 实现吗?

最佳答案

 public void btnPing_Click(object sender, EventArgs e)
{
try
{
int intCount = 0;
int maxip = 0;
richTmp.Clear();
string strIP = null;
string machineName = string.Empty;
List<string> strListIp = new List<string>();
List<string> txtBuffrFile = new List<string>();
BufferdIp = new List<string>();

for (int i = 1; i <= 30; i++)
{
System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
lstDetails.Items.Add("System Found: " + maxip);
System.Net.NetworkInformation.PingReply rep = p.Send("192.168.1." + i,500);
if (rep.Status == System.Net.NetworkInformation.IPStatus.Success)
{
intCount++;
lstDetails.Items.Clear();
lstDetails.Items.Add("Loading...Total(" + maxip+")");
strIP = rep.Address.ToString();
machineName = GetMachineNameFromIPAddress(strIP);
if (machineName == string.Empty || machineName == null)
{
strListIp.Add(strIP + ":-" + "Offline");
BufferdIp.Add("0");
}
else
{
strListIp.Add(strIP + ":-" + machineName+"(Online)");
BufferdIp.Add(strIP);
txtBuffrFile.Add(strIP);
maxip++;
}
}

}
lstDetails.Items.Clear();
foreach (var IDAddres in strListIp)
{
lstDetails.Items.Add(IDAddres);
}
for (int i = 0; i != txtBuffrFile.Count;i++ )
{
richTmp.Text += txtBuffrFile.ElementAt(i) + "\n";
}
if (MessageBox.Show("Do you want to Save This Search", "Save Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == (DialogResult.Yes))
{
if(File.Exists (path))
File.Delete(path);
FileStream stream = File.Create(path);
stream.Close();
File.WriteAllText(path, richTmp.Text, Encoding.UTF8);

}
btnConnct.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

我用它在我的 LAN 区域中 ping 但问题是只有当你知道 IP 模式和范围时它才有效:(

关于javascript - 如何在 MVC 的 C# 中使用本地 IP 地址扫描客户机的开放端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38714892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com