C# 通过url获得ip地址
2008-01-23 15:27
591 查看
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
public partial class Admin_BBSYear : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ip = "www.sina.com";
this.Label1.Text = CmdPing(ip);
}
private static string CmdPing(string strIp)
{
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;
string pingrst;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + strIp);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if (strRst.IndexOf("(0% loss)") != -1)
{
pingrst = "连接";
int start = strRst.IndexOf("Reply from");
int end = strRst.IndexOf(": bytes=");
pingrst = strRst.Remove(end);
pingrst = pingrst.Substring(start+10);
}
else if (strRst.IndexOf("Destination host unreachable.") != -1)
pingrst = "无法到达目的主机";
else if (strRst.IndexOf("Request timed out.") != -1)
pingrst = "超时";
else if (strRst.IndexOf("Unknown host") != -1)
pingrst = "无法解析主机";
else
pingrst = strRst;
p.Close();
return pingrst;
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
public partial class Admin_BBSYear : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ip = "www.sina.com";
this.Label1.Text = CmdPing(ip);
}
private static string CmdPing(string strIp)
{
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;
string pingrst;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + strIp);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if (strRst.IndexOf("(0% loss)") != -1)
{
pingrst = "连接";
int start = strRst.IndexOf("Reply from");
int end = strRst.IndexOf(": bytes=");
pingrst = strRst.Remove(end);
pingrst = pingrst.Substring(start+10);
}
else if (strRst.IndexOf("Destination host unreachable.") != -1)
pingrst = "无法到达目的主机";
else if (strRst.IndexOf("Request timed out.") != -1)
pingrst = "超时";
else if (strRst.IndexOf("Unknown host") != -1)
pingrst = "无法解析主机";
else
pingrst = strRst;
p.Close();
return pingrst;
}
}
相关文章推荐
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- C#通过域名获得IP地址的方法
- c# 通过访问URL,获取并解析远程服务端返回的复杂Json数据
- C# 通过代理获取url数据
- [C#]通过方法获得游戏人数和玩家姓名
- C# WinForm 通过URL取得服务器上的某图片文件到本地
- Java输出通过InetAddress获得的IP地址数组详细解析
- C#怎样通过url调用接口
- C#中使用正则表达式验证Email格式、IP地址格式和URL网址格式
- C# WinForm 通过URL取得服务器上的某图片文件到本地
- 通过javascript获得url参数
- Android 视频开发中如何通过url或者本地视频文件路径获得视频的第一帧图片
- Java-通过IP地址获得域名和主机名
- C#+arcengine实现输出水深图的功能(通过淹没区域和dem高程数据)(包含栅格计算器(减)、feature to line、产生随机点、获得高程、extract values to poin)
- [置顶] C#中通过调用webService获取上网IP地址的区域的方法
- <转载>C# 验证IP地址、Email格式、URl网址
- [CF.Skills]C#中如何通过RIL获得基站信息
- win7无法通过DHCP获得IP地址
- C#中IP地址的获得