C # gets all the IP addresses for this machine and filters the intranet IP

Source: Internet
Author: User

Private voidInitialization_load (Objectsender, EventArgs e) {Cboxip. Items.Add ("Please select an IP address"); List<string> str =Newlist<string>(); stringHostName = Dns.gethostname ();//name of the machine//system.net.ipaddress[] AddressList = Dns.gethostbyname (hostName). AddressList;//warns that gethostbyname () is out of date, I run and returns only one IPV4 addresssystem.net.ipaddress[] AddressList = dns.gethostaddresses (hostName);//will return all addresses, including IPv4 and IPv6            foreach(IPAddress IPinchAddressList) {                string_TEMP_IP =IP. MapToIPv4 ().                ToString (); string[] Ipstr = _temp_ip. Split ('.'); if(ipstr[0] =="127"|| ipstr[0] =="Ten"|| ipstr[0] =="172")                {                    Continue; }                Else {                    stringtemp = str. Where (s = = = =_temp_ip).                    FirstOrDefault (); if(temp = =NULL) {str.                        ADD (_TEMP_IP); Cboxip.                    Items.Add (_TEMP_IP); }}} cboxip. SelectedIndex=0; }

C # gets all the IP addresses for this machine and filters the intranet IP

Related Article

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.