C # get IPV4 code

Source: Internet
Author: User

Using system;using system.collections.generic;using system.collections.specialized;using System.ComponentModel; Using system.data;using system.drawing;using system.linq;using system.net;using system.net.sockets;using System.Text ; using system.threading.tasks;using system.windows.forms;namespace getipv4application{public partial class Form1:for        m {public Form1 () {InitializeComponent ();        } private void Btn_getipv4_click (object sender, EventArgs e) {Showip (); } void Showip () {Richtextboxipv4.text = string.            Empty; The IPv4 address may also be more than one foreach (String IP in GetLocalIpv4 ()) {This.richTextBoxIPv4.Append Text (IP.            ToString () + "\ n");        } return; } string[] GetLocalIpv4 () {//Do not know the number of IP in advance, the array length is unknown, so use StringCollection to store ipaddress[] Lo            Calips; Localips = Dns.gethostaddresses (Dns.gethostname ());            StringCollection ipcollection = new StringCollection ();                  foreach (IPAddress IP in localips) {//Based on addressfamily to determine if IPv4, if InterNetWorkV6 is IPv6 if (IP. AddressFamily = = addressfamily.internetwork) ipcollection.add (IP.            ToString ());            } string[] Iparray = new String[ipcollection.count];            Ipcollection.copyto (Iparray, 0);        return iparray; }    }}

  

Note: Multiple IP addresses are obtained when a virtual network card is available.

C # get IPV4 code

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.