Saturday, November 22, 2008
NSLookup without additional server components
Project Rating:





This code will make an IP lookup without the need of a special nslookup component on the server, it only uses the XML parser available with Internet Explorer 5.0 and above (which should be installed on the server.
|
<% Dim objXMLHTTP, xml Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP") xml.Open "POST", "http://www.csu.net/cgi-bin/nslookup?"&request("ip"), false xml.Send orgLine = xml.responseText Set xml = Nothing
dim HTML_lines
HTML_lines = Split(orgLine, vbLf) if UBound(HTML_lines) < 2 then HTML_lines = Split(orgLine, vbLf) if UBound(HTML_lines) < 2 then HTML_lines = Split(orgLine, vbCrLf) end if end if
host = "" ip = ""
for i = 0 to ubound(HTML_lines) line = trim(HTML_lines(i)) if left(line,5) = "Name:" then host = trim(mid(line, 6)) ip = trim(mid(trim(HTML_lines(i+1)), 9)) exit for end if next if host = "" then host = "Unknown"
response.write host & " " & ip %>
|
To try a demo of this code, click here*
Comments?
* The service to resolve dns names stopped working, this code can be ported to any other nslookup service online, some need that you change how you parse the response.