Get the native extranet IP
1 //get the public IP of this machine2 Public Static stringGetIP ()3 {4 stringTempip ="";5 Try6 {7WebRequest request = WebRequest.Create ("http://ip.qq.com/");8Request. Timeout =10000;9WebResponse response =request. GetResponse ();TenStream Resstream =Response. GetResponseStream (); OneStreamReader sr =NewStreamReader (Resstream, System.Text.Encoding.Default); A stringHtmlinfo =Sr. ReadToEnd (); - //Regular expressions that match an IP -Regex r =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); theMatch MC =R.match (htmlinfo); - //get the IP that matches to -Tempip = MC. groups[0]. Value; - + resstream.close (); - Sr. Close (); + } A Catch(Exception Err) at { -Tempip =Err. Message; - } - returnTempip; -}
Get the native intranet IP
//Get intranet IP Private stringGetinternalip () {Iphostentry host; stringLocalip ="?"; Host=Dns.gethostentry (Dns.gethostname ()); foreach(IPAddress IPinchhost. AddressList) {if(IP. addressfamily.tostring () = ="Internetwork") {Localip=IP. ToString (); Break; } } returnLocalip; }
Get the native extranet IP and intranet IP