namespace IPExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
string name = Dns.GetHostName();
listBox1.Items.Add("本机主机名:" + name);
IPHostEntry me = Dns.GetHostEntry(name);
listBox1.Items.Add("本机所有IP地址:");
foreach (IPAddress ip in me.AddressList)
{
listBox1.Items.Add(ip);
}
IPAddress localip = IPAddress.Parse("127.0.0.1");
IPEndPoint iep = new IPEndPoint(localip, 80);
listBox1.Items.Add("The IPEndPoint is: " + iep.ToString());
listBox1.Items.Add("The Address is: " + iep.Address);
listBox1.Items.Add("The AddressFamily is: " + iep.AddressFamily);
listBox1.Items.Add("The max port number is: " + IPEndPoint.MaxPort);
listBox1.Items.Add("The min port number is: " + IPEndPoint.MinPort);