c#如何来判断本机与指定IP计算机是否相通
3个回答
展开全部
我做了个例子 ,你要源码的话我可以给你源码
但我还是附上代码
try
{
Ping p = new Ping();
PingReply reply = p.Send(this.textBox1.Text);
//this.textBox.Text写上目标ip地址就行
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("成功!");
}
else
{
MessageBox.Show("失败!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
但我还是附上代码
try
{
Ping p = new Ping();
PingReply reply = p.Send(this.textBox1.Text);
//this.textBox.Text写上目标ip地址就行
if (reply.Status == IPStatus.Success)
{
MessageBox.Show("成功!");
}
else
{
MessageBox.Show("失败!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP...
点击进入详情页
本回答由Storm代理提供
展开全部
根据ping的结果判断
单击开始、运行、输入CMD、然后输入
D:\>ping 100.1.0.13
Pinging 100.1.0.13 with 32 bytes of data:
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Ping statistics for 100.1.0.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
以上的结果就是可以ping 通的
以下的结果就是ping 不通的
D:\>ping 100.1.0.185
Pinging 100.1.0.185 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 100.1.0.185:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
从ping的结果中可以大致判断对方机器的系统等。
详细可以用ping/all来了解。
单击开始、运行、输入CMD、然后输入
D:\>ping 100.1.0.13
Pinging 100.1.0.13 with 32 bytes of data:
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Reply from 100.1.0.13: bytes=32 time<1ms TTL=128
Ping statistics for 100.1.0.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
以上的结果就是可以ping 通的
以下的结果就是ping 不通的
D:\>ping 100.1.0.185
Pinging 100.1.0.185 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 100.1.0.185:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
从ping的结果中可以大致判断对方机器的系统等。
详细可以用ping/all来了解。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调用ping命令来完成网络检测
//调用ping命令
private string[,] Ping(string [] ips)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
int i = 0;
int lines = ips.Length;
string[,] pingResult= new [lines,2];
for(;i<lines;i++)
{
string pingrst = null;
p.Start();
p.StandardInput.WriteLine("ping -n 1 "+ips[i]);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if(strRst.IndexOf("(0% loss)")!=-1)
{
pingrst = "连接";
}
else if( strRst.IndexOf("Destination host unreachable.")!=-1)
{
pingrst = "无法到达";
}
else if(strRst.IndexOf("Request timed out.")!=-1)
{
pingrst = "断开";
}
else
{
pingrst = "无法解析";
}
pingResult[i,0] = ips[i];
pingResult[i,1] = pingrst;
}
p.Close();
return pingResult;
}
调用系统的PING的程序.判断返回值
//调用ping命令
private string[,] Ping(string [] ips)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
int i = 0;
int lines = ips.Length;
string[,] pingResult= new [lines,2];
for(;i<lines;i++)
{
string pingrst = null;
p.Start();
p.StandardInput.WriteLine("ping -n 1 "+ips[i]);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if(strRst.IndexOf("(0% loss)")!=-1)
{
pingrst = "连接";
}
else if( strRst.IndexOf("Destination host unreachable.")!=-1)
{
pingrst = "无法到达";
}
else if(strRst.IndexOf("Request timed out.")!=-1)
{
pingrst = "断开";
}
else
{
pingrst = "无法解析";
}
pingResult[i,0] = ips[i];
pingResult[i,1] = pingrst;
}
p.Close();
return pingResult;
}
调用系统的PING的程序.判断返回值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询