日期:2014-05-18  浏览次数:21025 次

winform中如何ping一个ip,看它是否有效?
我是用winform开发pda的,想在连接服务器之前,先ping一下ip,看它是否是有效的,然后再连接.请各位高手多多指教!谢谢!

------解决方案--------------------
Process.Start("cmd.exe","ping 192.168.100.101");
------解决方案--------------------
pda....又没看清楚
pda上没那个功能
------解决方案--------------------
我以前做FTP上传的时候是用Socket通道,在Progress类的对象里存放的是Dos命令,

理论上Ping的命令放进去也可以的.
------解决方案--------------------
code=C#]
try
{
//ping
return true;
}
catch
{
return false;
}
[/code]
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAssistants.NetFtp
{

public class ClassRunEXE
{

#region 基本构造函数
/// <summary>
/// 构造函数
/// </summary>
/// <param name="exeFileName">exe文件</param>
/// <param name="Arguments">参数</param>
// 用法:RunEXE("C:\Program Files\WinRAR\WinRAR.exe", "a -ep e:\test\20080612.rar E:\test\20080612\*.*")


public static void RunEXE(string exeFileName, string arguments)
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();

//设置外部程序名
Info.FileName = exeFileName;
//设置外部程序的启动参数(命令行参数)
Info.Arguments = arguments;
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
//启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
}
catch (Exception ex)
{
//MessageBox.Show("系统找不到指定的程序文件。");
System.Windows.Forms.MessageBox.Show(ex.Message, "系统找不到指定的程序文件。");
return;
}

//等待完成
Proc.WaitForExit();

}
#endregion
}
}