Experience: http://tool.hovertree.com/info/ip/
The code is as follows:
1 usingSystem;2 usingSystem.Text;3 usingSystem.Text.RegularExpressions;4 usingsystem.web;5 6 namespaceHoverTree.HoverTreeFrame.HvtNet7 {8 Public classHovertreeip9 {Ten /// <summary> One ///Get real IP A /// </summary> - /// <returns></returns> - Public Static stringGethovertreeip () the{//http://tool.hovertree.com/info/ip/ - stringresult = httpcontext.current.request.servervariables["http_x_forwarded_for"]; - if(NULL= = Result | | result = =String.Empty) - { +result = httpcontext.current.request.servervariables["REMOTE_ADDR"]; - } + if(NULL= = Result | | result = =String.Empty) A { atresult =HttpContext.Current.Request.UserHostAddress; - } - returnresult; - } - - Public Static BOOLHvtisip (stringIP) in { - returnRegex.IsMatch (IP,@"^ ((23[0-3]|1\d{2}|[ 1-9]\d| [1-9]) \.) ((25[0-5]|2[0-4]\d|1?\d{1,2}) \.) {2} ((25[0-5]|2[0-4]\d|1?\d{1,2})) $") ; to } + - /// <summary> the ///Convert IP address to integer hovertree.com * /// </summary> $ /// <param name= "IP" ></param>Panax Notoginseng /// <returns></returns> - Public Static LongHvtiptolong (stringIP) the { + Char[] Separator =New Char[] {'.' }; A string[] items =IP. Split (separator); the return Long. Parse (items[0]) << - +|Long. Parse (items[1]) << - -|Long. Parse (items[2]) <<8 $|Long. Parse (items[3]); $ } - - /// <summary> the ///turn an integer into an IP what to ask - /// </summary>Wuyi /// <param name= "Iplong" ></param> the /// <returns></returns> - Public Static stringHvtlongtoip (LongIplong) Wu{//http://hovertree.com/hvtart/bjae/cn5qrmxw.htm -StringBuilder SB =NewStringBuilder (); AboutSb. Append (Iplong >> -) &0xFF). Append ("."); $Sb. Append (Iplong >> -) &0xFF). Append ("."); -Sb. Append (Iplong >>8) &0xFF). Append ("."); -Sb. Append (Iplong &0xFF); - returnsb. ToString (); A } +}
The code for the class will be published in the HOVERTREECMS project.
Asp. NET open source CMS http://www.cnblogs.com/sosoft/p/cms.html
Develop technical articles to collect http://www.cnblogs.com/sosoft/p/kaifajishu.html
C # get IP and integer IP methods