/// <summary> ///function: Get the local extranet IP address///Yellow Sea///Time: 2016-07-22/// </summary> /// <returns></returns> Private Static stringGetpublicip () {varUrllist =Newlist<string> { "http://ip.qq.com/", "Http://pv.sohu.com/cityjson?ie=utf-8", "Http://ip.taobao.com/service/getIpInfo2.php?ip=myip" }; varTempip =""; foreach(varAinchurllist) { Try { varreq =WebRequest.Create (a); Req. Timeout=20000; varResponse =req. GetResponse (); varResstream =Response. GetResponseStream (); if(Resstream! =NULL) { varSR =NewStreamReader (Resstream, Encoding.UTF8); varHtmlinfo =Sr. ReadToEnd (); //Regular expressions that match an IP varR =NewRegex ("((25[0-5]|2[0-4]\\d|1\\d\\d|[ 1-9]\\d|\\d) \ \.) {3} (25[0-5]|2[0-4]\\d|1\\d\\d| [1-9]\\d| [1-9])", Regexoptions.none); varMC =R.match (Htmlinfo); //get the IP that matches toTempip = MC. groups[0]. Value; Resstream.close (); Sr. Close (); Response. Dispose (); } returnTempip; } Catch(Exception Err) {Console.WriteLine ("current probe URL:"+a+", error description:"+Err. ToString ()); } } returnTempip; }
C # Gets the native IP of the extranet