- using System;
- using System.Net;
- using System.Text.RegularExpressions;
- namespace GetInternetIP
- {
- public class GetInternetIP
- {
- public static string GetIP()
- {
- using (var webClient = new WebClient())
- {
- try
- {
- var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");
- return Regex.Match(temp, @"\\[(?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+)]").Groups["ip"].Value;
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0112201514162.html
来源: http://www.codesnippet.cn/detail/0112201514162.html