PowerTCP Sockets for .NET
MxHostEntry Class
Members  Example 




Provides the HostName and Preference provided by an MX record lookup.
Object Model
MxHostEntry Class
Syntax
'Declaration
 
Public Class MxHostEntry 
'Usage
 
Dim instance As MxHostEntry
public class MxHostEntry 
public __gc class MxHostEntry 
public ref class MxHostEntry 
Example
The following example demonstrates performing a DNS lookup of a provided hostname, and an MX record lookup of a provided email address.
private void button1_Click(object sender, EventArgs e)
{
    dns1.Start(doMxLookup, EmailToResolveTextbox.Text);
}

private void button2_Click(object sender, EventArgs e)
{
    dns1.Start(doHostLookup, HostToResolveTextbox.Text);
}

/// <summary>
/// Performs an MX record lookup of the provided email address.
/// </summary>
/// <param name="slave">Object used to perform DNS lookup</param>
/// <param name="state">Passed in from the 2nd parameter of Dns.Start(). Email address to lookup.</param>
private void doMxLookup(DnsSlave slave, object state)
{
    MxHostEntry[] hostEntries = slave.GetMxHostEntries(state.ToString());
    string results = "The following mail servers were returned for " + state.ToString() + ":" + Environment.NewLine;
    foreach (MxHostEntry hostEntry in hostEntries)
        results += hostEntry.HostName + " : Preference: " + hostEntry.Preference.ToString() + Environment.NewLine;
    //Marshal result to the UI for display
    dns1.Marshal(results, null);
}

/// <summary>
/// Performs a DNS lookup of the provided hostname.
/// </summary>
/// <param name="slave">Object used to perform DNS lookup</param>
/// <param name="state">Passed in from the 2nd parameter of Dns.Start(). Hostname to lookup.</param>
private void doHostLookup(DnsSlave slave, object state)
{
    System.Net.IPHostEntry hostEntry = slave.GetHostEntry(state.ToString());
    string results = "The following IP addresses were returned for " + state.ToString() + ":" + Environment.NewLine;
    foreach (System.Net.IPAddress address in hostEntry.AddressList)
        results += address.ToString() + Environment.NewLine;
    //Marshal result to the UI for display
    dns1.Marshal(results, null);
}

/// <summary>
/// Raised when Dns.Marshal(string, object) is called.
/// </summary>
private void dns1_UserState(object sender, UserStateEventArgs e)
{
    textBox1.AppendText(e.Message + Environment.NewLine);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    dns1.Start(AddressOf doMxLookup, EmailToResolveTextbox.Text)
End Sub

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    dns1.Start(AddressOf doHostLookup, HostToResolveTextbox.Text)
End Sub

''' <summary>
''' Performs an MX record lookup of the provided email address.
''' </summary>
''' <param name="slave">Object used to perform DNS lookup</param>
''' <param name="state">Passed in from the 2nd parameter of Dns.Start(). Email address to lookup.</param>
Private Sub doMxLookup(ByVal slave As DnsSlave, ByVal state As Object)
    Dim hostEntries() As MxHostEntry = slave.GetMxHostEntries(state.ToString())
    Dim results As String = "The following mail servers were returned for " & state.ToString() & ":" & Environment.NewLine
    For Each hostEntry As MxHostEntry In hostEntries
        results &= hostEntry.HostName & " : Preference: " & hostEntry.Preference.ToString() & Environment.NewLine
    Next hostEntry
    'Marshal result to the UI for display
    dns1.Marshal(results, Nothing)
End Sub

''' <summary>
''' Performs a DNS lookup of the provided hostname.
''' </summary>
''' <param name="slave">Object used to perform DNS lookup</param>
''' <param name="state">Passed in from the 2nd parameter of Dns.Start(). Hostname to lookup.</param>
Private Sub doHostLookup(ByVal slave As DnsSlave, ByVal state As Object)
    Dim hostEntry As System.Net.IPHostEntry = slave.GetHostEntry(state.ToString())
    Dim results As String = "The following IP addresses were returned for " & state.ToString() & ":" & Environment.NewLine
    For Each address As System.Net.IPAddress In hostEntry.AddressList
        results &= address.ToString() & Environment.NewLine
    Next address
    'Marshal result to the UI for display
    dns1.Marshal(results, Nothing)
End Sub

''' <summary>
''' Raised when Dns.Marshal(string, object) is called.
''' </summary>
Private Sub dns1_UserState(ByVal sender As Object, ByVal e As UserStateEventArgs)
    textBox1.AppendText(e.Message & Environment.NewLine)
End Sub
Inheritance Hierarchy

System.Object
   Dart.Sockets.MxHostEntry

See Also

Reference

MxHostEntry Members
Dart.Sockets Namespace


PowerTCP Sockets for .NET Documentation Version 4.5
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic