using System.Net
using System.Net.NetworkInformation
class Program
{
static void Main(string[] args)
{
int count = 4
IPAddress addr = IPAddress.Parse("220.181.111.86")
Ping ping = new Ping()
long timeSum = 0
int succCount = 0
//发送
Console.WriteLine("正在ping {0}", addr)
for (int i = 0i <count++i)
{
PingReply pr = ping.Send(addr)
if (pr.Status == IPStatus.TimedOut)
Console.WriteLine("超时")
else if (pr.Status == IPStatus.Success)
{
Console.WriteLine("延时:{0}毫秒", pr.RoundtripTime)
++succCount
timeSum += pr.RoundtripTime
}
}
if (timeSum != 0)
Console.WriteLine("平均延时{0}毫秒,丢包率{1}%", 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count)
else
Console.WriteLine("丢包率100%")
return
}
}
用system函数简单调用ping命令:#include "stdio.h"
void main()
{
char ip[15]
char command[50]
// printf("enter IP please: ")
scanf("%s",&ip[0])//输入要ping的ip
sprintf(command,"ping %s",ip)
system(command)
exit(0)
}
.版本 2运行 (“cmd /c ping ” + 编辑框1.内容 + “-t” + “ >c:\ping.txt”, 真, #隐藏窗口)
编辑框2.内容 = 到文本 (读入文件 (“c:\ping.txt”))
删除文件 (“c:\ping.txt”)
.否则
.如果结束
是用CMD的保存文件。读取CMD的保存文件。原理就是这样
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)