在c#中,我使用web客户端类打开html。在html中有特定In。我想搜索我的本机IP
WebClient wbclint = new WebClient();
value1 = wbclint.DownloadString("foo.html");
Console.WriteLine("testing");
Console.ReadKey(true);那么如何使用这个web客户端来捕获特定的ip呢?
发布于 2012-10-13 02:47:50
使用正则表达式来搜索字符串,http://msdn.microsoft.com/en-us/library/ms228595%28v=vs.80%29.aspx这里有一个在c#中使用正则表达式执行类似操作的示例;用来验证电话号码。
发布于 2012-10-13 02:59:06
public class Test
{
public static void Main (string[] args)
{
if (args == null || args.Length == 0)
{
throw new ApplicationException ("Specify the URI of the resource to retrieve.");
}
var client = new WebClient ();
var s = client.DownloadString (args[0]);
// var data = client.OpenRead(args[0]);
// var reader = new StreamReader(data);
// var s = reader.ReadToEnd();
var myIP = "100.100.100.100";
var ipFound = s.Contains(myIP);
Console.WriteLine("Is my IP in the web page?: {0}", ipFound );
data.Close ();
reader.Close ();
}
}https://stackoverflow.com/questions/12865193
复制相似问题