An
.asp
file is an old-school "classic" ASP page. It runs VBScript, which is an ancient language with very few built-in tools.
The code in your
GetHostname.asp
file is C#; that will only work in an ASP.NET page.
You could try renaming your file to
GetHostname.aspx
and replacing the first line (
<!-- metadata ... -->
) with:
<%@ Page Language="C#" %>
Whether that works will depend on whether or not your server has the .NET Framework installed, and the IIS site has "managed code" enabled. If you're on a server that's as old as the code, that may not be the case.
Edit: The corrected C# code would look something like:
<%@ Page Language="C#" %>
<%
string hostName = Request.UserHostName;
if (string.IsNullOrEmpty(hostName))
{
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ipAddress)) ipAddress = Request.UserHostAddress;
try
{
System.Net.IPHostEntry entry = System.Net.Dns.GetHostEntry(ipAddress);
hostName = entry.HostName;
}
catch
{
hostName = ipAddress;
}
}
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>WKS/LTP Name</title>
<script>
window.resizeTo(500, 150);
window.moveTo(350, 300);
</script>
<style>
h1 {
font-size: 60rem;
font-family: Verdana;
}
</style>
</head>
<body>
<h1>
WKS/LTP Name is:
<%= HttpUtility.HtmlEncode(hostName) %>
</h1>
</body>
</html>
NB: You need to HTML-encode the host name, just in case it contains any "special" characters.