Skip to content

Instantly share code, notes, and snippets.

@davideicardi
Last active September 1, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davideicardi/6d3f5bf45efaeea0e2a03cba58beec5f to your computer and use it in GitHub Desktop.
Save davideicardi/6d3f5bf45efaeea0e2a03cba58beec5f to your computer and use it in GitHub Desktop.
Host name resolution diagnostic page
<!-- directives -->
<% @Page Language="C#" %>
<%@ Import namespace="System.Net" %>
<!-- call example:
https://server/_diagnostics/dns.aspx?hostName=microsoft.com
-->
<script runat="server">
private string HostName2IP(string hostname)
{
var iphost = System.Net.Dns.GetHostEntry(hostname);
var addresses = iphost.AddressList;
var addressList = new System.Text.StringBuilder( );
foreach(var address in addresses)
{
addressList.Append("IP Address: ");
addressList.Append(address.ToString( ));
addressList.Append(";");
}
return addressList.ToString( );
}
private void Resolve(string hostName, int executionCount)
{
outputText.InnerHtml = "";
outputText.InnerHtml += "RESOLVING " + hostName + " <br/>";
for (int i = 0; i < executionCount; i++)
{
try
{
outputText.InnerHtml += " SUCCESSFUL " + HostName2IP(hostName);
outputText.InnerHtml += "<br/>";
}
catch (Exception ex)
{
outputText.InnerHtml += "FAILED " + ex.ToString() + " <br/>";
}
}
}
private void ResolveClick(object sender, EventArgs e)
{
var executionCountInt = int.Parse(executionCount.Value);
Resolve(hostName.Value, executionCountInt);
}
private void Page_Load()
{
var hostName = Request.QueryString["hostName"];
if (string.IsNullOrWhiteSpace(hostName)) return;
var executionCount = Request.QueryString["executionCount"] ?? "1";
var executionCountInt = int.Parse(executionCount);
Resolve(hostName, executionCountInt);
}
</script>
<html>
<head>
<title> Resolve Host Test </title>
</head>
<body>
<h3> Resolve Host Test </h3>
<p>Machine name: <%= System.Environment.MachineName %></p>
<form runat="server">
<h4>Host Name</h4>
<input runat="server" id="hostName" type="text" value="google.com" style="width:300px" />
<br />
<h4>Retry count</h4>
<input runat="server" id="executionCount" type="text" value="1" />
<br />
<input runat="server" id="button1" type="submit" value="Resolve" OnServerClick="ResolveClick" />
<hr />
<h3> Results: </h3>
<span runat="server" id="outputText" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment