本地IP

来源:互联网 发布:人工智能 电影 编辑:程序博客网 时间:2024/05/01 21:30
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace 本地IP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IPHostEntry myhost = new IPHostEntry();
            try
            {
                myhost = Dns.GetHostEntry(Dns.GetHostName());
               //textBox1.Text = myhost.HostName; //主机名
                for (int i = 0; i < myhost.AddressList.Length; i++)
                {
                    textBox1.Text += myhost.AddressList[i].ToString();
                }
            }
            catch
            {
                MessageBox.Show("请检查网络", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
    }
}