C#怎么判断电脑是否联网了?
3个回答
2013-07-18
展开全部
判断联网有多种方式,最常用的就是ping IP地址,ping IP地址又有多种方式,其中之一,用dos命令,而是用程序,也就是在C#中主要的代码如下主要是用到命令空间 using System.Net.NetworkInformation下的ping类 Ping ping = new Ping();
for (int i = iFrom; i <= iTo; i++)
{
mre1.WaitOne();
string ip = strIP + i.ToString();
label10.Text = "正在扫描主机:" + ip.ToString() ;
try
{
PingReply reply = ping.Send(ip, 100);
if (reply.Status == IPStatus.Success)
{
rtbInfo.AppendText("Host: " + ip.ToString() + "\r");
rtbInfo.ScrollToCaret();
}
}
catch {
rtbInfo.AppendText("发生了一个异常!\r");
}
}
rtbInfo.AppendText("扫描完毕!\r");
for (int i = iFrom; i <= iTo; i++)
{
mre1.WaitOne();
string ip = strIP + i.ToString();
label10.Text = "正在扫描主机:" + ip.ToString() ;
try
{
PingReply reply = ping.Send(ip, 100);
if (reply.Status == IPStatus.Success)
{
rtbInfo.AppendText("Host: " + ip.ToString() + "\r");
rtbInfo.ScrollToCaret();
}
}
catch {
rtbInfo.AppendText("发生了一个异常!\r");
}
}
rtbInfo.AppendText("扫描完毕!\r");
2013-07-18
展开全部
c#自带的Ping,using System.Net.NetworkInformation;
Ping ping = new Ping();
for (int i = iFrom; i <= iTo; i++)
{
mre1.WaitOne();
string ip = strIP + i.ToString();
label10.Text = "正在扫描主机:" + ip.ToString() ;
try
{
PingReply reply = ping.Send(ip, 100);
if (reply.Status == IPStatus.Success)
{
rtbInfo.AppendText("Host: " + ip.ToString() + "\r");
rtbInfo.ScrollToCaret();
}
}
catch {
rtbInfo.AppendText("发生了一个异常!\r");
}
}
rtbInfo.AppendText("扫描完毕!\r");
Ping ping = new Ping();
for (int i = iFrom; i <= iTo; i++)
{
mre1.WaitOne();
string ip = strIP + i.ToString();
label10.Text = "正在扫描主机:" + ip.ToString() ;
try
{
PingReply reply = ping.Send(ip, 100);
if (reply.Status == IPStatus.Success)
{
rtbInfo.AppendText("Host: " + ip.ToString() + "\r");
rtbInfo.ScrollToCaret();
}
}
catch {
rtbInfo.AppendText("发生了一个异常!\r");
}
}
rtbInfo.AppendText("扫描完毕!\r");
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-18
展开全部
在运行里打入:IPCONFIG /ALL
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询