C # Random acquisition of domestic IP

Source: Internet
Author: User

Call the Getrandomip () method to
Framework3.5 + Using LINQ

 Public stringGetrandomip () {/*int[][] This is called a jagged array, and vernacular is an array of arrays. Initialize method: int[][] numbers = new int[][] {new int[] {2,3,4}, new int[] {5,6,7,8,9}}; Of course you can also initialize int[][with the {} initializer     ] numbers = {new int[] {2,3,4}, new int[] {5,6,7,8,9}}; */         int[] Range = {New int[]{607649792,608174079},//36.56.0.0-36.63.255.255New int[]{1038614528,1039007743},//61.232.0.0-61.237.255.255New int[]{1783627776,1784676351},//106.80.0.0-106.95.255.255New int[]{2035023872,2035154943},//121.76.0.0-121.77.255.255New int[]{2078801920,2079064063},//123.232.0.0-123.235.255.255New int[]{-1950089216,-1948778497},//139.196.0.0-139.215.255.255New int[]{-1425539072,-1425014785},//171.8.0.0-171.15.255.255New int[]{-1236271104,-1235419137},//182.80.0.0-182.92.255.255New int[]{-770113536,-768606209},//210.25.0.0-210.47.255.255 New int[]{-569376768,-564133889},//222.16.0.0-222.95.255.255}; Random Rdint=NewRandom (); intindex = Rdint. Next (Ten); stringip = Num2ip (range[index][0] +NewRandom (). Next (range[index][1]-range[index][0])); returnIP; }         /** Convert decimal to IP address*/         Public stringNum2ip (intIP) {            int[] B =New int[4]; stringx =""; //displacement is then converted to high and low positions with 255.b[0] = (int) ((IP >> -) &0xFF); b[1] = (int) ((IP >> -) &0xFF); b[2] = (int) ((IP >>8) &0xFF); b[3] = (int) (IP &0xFF); X= (b[0]). ToString () +"."+ (b[1]). ToString () +"."+ (b[2]). ToString () +"."+ (b[3]).             ToString (); returnx; }

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication1{classProgram {Staticdictionary<int,int> ips =New int[] {Enumerable.range (607649792,608174079-607649792+1). ToArray (), Enumerable.range (1038614528,1039007743-1038614528+1). ToArray (), Enumerable.range (1783627776,1784676351-1783627776+1). ToArray (), Enumerable.range (2035023872,2035154943-2035023872+1). ToArray (), Enumerable.range (2078801920,2079064063-2078801920+1). ToArray (), Enumerable.range (-1950089216, -1948778497+1950089216+1). ToArray (), Enumerable.range (-1425539072, -1425014785+1425539072+1). ToArray (), Enumerable.range (-1236271104, -1235419137+1236271104+1). ToArray (), Enumerable.range (-770113536, -768606209+770113536+1). ToArray (), Enumerable.range (-569376768, -564133889+569376768+1). ToArray ()}. SelectMany (x= x). Select ((x, i) = =New{x, i}). ToDictionary (x = x.i, x = =x.x); Static stringIptostring (intIP) {            return string. Join (".", Bitconverter.getbytes (IP). Reverse (). Select (x = (int) x).        ToString ())); }         Static intGenip () {returnips[NewRandom (Guid.NewGuid (). GetHashCode ()). Next (0, IPs.        Count)]; }         Static voidMain (string[] args) {             for(inti =0; I <Ten; i++) Console.WriteLine (Iptostring (Genip ())); }    }}

Add a comment that is not easy to understand section: The students who want to figure it out now must understand.

C # Random acquisition of domestic IP

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.