Visual C # IP related Operations class, to obtain the current client IP, to determine the IP format, that is, detect whether the IP address, some of the basic operation of IP, welcome C # Novice Reference:
01///
02///gets the IP of the current page client
03///
04///The current page client's IP
05public static string GetIP ()
269
Modified string result = String.Empty;
result = httpcontext.current.request.servervariables["http_x_forwarded_for"];
if (Null = result | | = = String.Empty)
10 {
One result = httpcontext.current.request.servervariables["REMOTE_ADDR"];
12}
if (Null = result | | = = String.Empty)
14 {
result = HttpContext.Current.Request.UserHostAddress;
16}
if (Null = result | |) result = = String.Empty | |! IsIP (Result))
18 {
return "0.0.0.0";
20}
return result;
22}
23///
Whether the 24///is IP
25///
26///
27///
28public static bool IsIP (string IP)
099
return Regex.IsMatch (IP, @ "^" (2[0-4]d|25[0-5]|[ 01]?dd?). {3} (2[0-4]d|25[0-5]| [01]?dd?] $");
31}