Simple implementation of C domain name resolution
- 2021-06-29 11:54:25
- OfStack
This paper describes a simple implementation of C#domain name resolution.Share it for your reference.The implementation is as follows:
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 test1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonDns_Click(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
// Resolve Host Name
IPHostEntry IPinfo = Dns.GetHostEntry(textBox1.Text);
// Empty List Box
listBox1.Items.Clear();
listBox2.Items.Clear();
// display IP address
foreach (IPAddress IP in IPinfo.AddressList)
{
listBox1.Items.Add(IP.ToString());
}
// Show Alias
foreach (string alias in IPinfo.Aliases)
{
listBox2.Items.Add(alias);
}
// Show hostname
textBox2.Text = IPinfo.HostName;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
I hope that the description in this paper will be helpful to everyone's C#program design.