Last active
September 1, 2016 15:22
-
-
Save davideicardi/6d3f5bf45efaeea0e2a03cba58beec5f to your computer and use it in GitHub Desktop.
Host name resolution diagnostic page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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