C # get IP and integer IP methods

Source: Internet
Author: User
Tags get ip servervariables open source cms

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.