Form1.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace WindowsFormsIPAddress
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. label2.Text = string.Empty;//初始化Label标签
  22. //获得指定主机的IP地址族
  23. IPAddress[] ips = Dns.GetHostAddresses(textBox1.Text);
  24. //循环遍历得到的IP地址
  25. foreach (IPAddress ip in ips)
  26. {
  27. //在Label标签中显示得到的IP地址信息
  28. label2.Text = "网际协议地址:" + ip.Address + "\nIP地址的地址族:"
  29. + ip.AddressFamily.ToString() + "\n是否IPv6链接本地地址:" + ip.IsIPv6LinkLocal;
  30. }
  31. }
  32. }
  33. }